
    Mg                     d    S SK r S SKJr  S SKJrJr  \" SS9\" S5       " S S5      5       5       rg)	    N)datetime)pluginrequireT)networksoccerc                   :    \ rS rSrSrSrSrS rS rS\	4S jr
S	rg)
Soccer   z
This plugin offers functionality to check upcoming and recently played matches for soccer competitions.
This plugin requires a free API key from football-data.org which can be acquired at football-data.org/client/register
Nz http://api.football-data.org/v4/c                    [        S5        [        S5      U l        [        R                  " U R
                  S-   SU R                  0S9nUR                  S:X  aP  [        S5      U l        [        R                  " U R
                  S-   SU R                  0S9nUR                  S:X  a  MP  [        5         U R                  5          [        S5      n[        5         US	:X  a  U R                  5         OUS
:X  a  g US:X  af  [        S5      U l        [        R                  " U R
                  S-   SU R                  0S9nUR                  S:X  a  [        S5        O[        S5        O U R                  U5        M  !   [        S5         N= f)Nz"
Powered by football-data.org APIszFEnter an API key by registering at football-data.org/client/register: zcompetitions/2013/matchesX-Auth-Tokenheadersi  zPlease enter a valid API key: zuEnter ID to view matches for a competition, \table to view competitions, \key to re-enter API key, or \exit to exit: z\tablez\exitz\key   zAPI Key is validated
zInvalid API key
zInvalid competition ID
)	printinputAPI_KEYrequestsgetBASE_URLstatus_codeget_competitionsget_matches)selfjarvisssample_requestcompetition_ids        </Users/admin/workspace/ai/Jarvis/jarviscli/plugins/soccer.py__call__Soccer.__call__   so   34ef!dmm6Q&Q^lnrnznz]{|((C/ !ABDL%\\$--:U*U`nptp|p|_}~N ((C/ 	"  $^  _NG*%%'8+7*$%mn!)dmm>Y.Ydrtx  uA  uA  dB  "C!--423-.6$$^4! "645s   %E8 8Fc           
         SU R                   0n[        R                  " U R                  S-   US9nUR                  S:X  aT  UR                  5       nUS   n[        SSS 35        U H  n[        SUS	   S
 SUS    SS S35        M!     [        5         g [        S[        UR                  5      -   5        [        5         g )Nr   competitionsr   r   z[90mz Competitions u   —^40[0mname<30z (ID: [90mid )z@Error retrieving API based data (most likely invalid API key) - )r   r   r   r   r   jsonr   str)r   r   responsepayloadr"   competitions         r   r   Soccer.get_competitions1   s    DLL
 << >P3&mmoG">2LH-f567+F 3C8{SWGXFYY`ac`ddefg  ,GTWZ[c[o[oWppqG    r   c                 x   [        5         SU R                  0n[        R                  " 5       nUR                  nUR
                  S:X  a  US-  nS[        UR                  5      -   nUR                  S:  a  SU-   nUR                   SUR
                   SU 3U SUR
                  S-   S-   SU 3S.nUR
                  S:  a!  UR                   S	UR
                   SU 3US
'   UR
                  S:  a  U S	UR
                  S-   S-   SU 3US'   U R                   SU S3n[        R                  " XvUS9nUR                  5       n	UR                  S:X  a  U	S   n
[        U
5      S:X  a  [        S5        g SnU
 H  nUS:X  a    g US-  nUS   S    SUS   S    S3nUS   S    SUS   S    S3nUS   S:H  nUS   S   S   nUS   S   S    nUc  S!nS!nUS"   n[        S#USS S$ 35        [        S%US& U S'U S!US( S)35        M     g [        S*[        UR                  5      -   5        [        5         g )+Nr         r'   
   0-)dateFromdateToz-0r6   	   r7   zcompetitions/z/matches)paramsr   r   matchesr   z-No match data available in the upcoming month   homeTeam	shortNamez (tlar(   awayTeamstatusFINISHEDscorefullTimehomeaway utcDater#   u   —^68z[94mr%   z  [0m--- [95mz>30
zGError retrieving API based data (most likely invalid competition ID) - )r   r   dtnowyearmonthr*   dayr   r   r   r)   r   len)r   r   r   curryear_torM   
parametersURLr+   r,   r:   countmatchrD   rE   finished
home_goals
away_goalstimes                      r   r   Soccer.get_matchesC   s   DLL
 vvx))::qLGTXX88b=)C#yyk4::,au=&iq$**q.")<(=QseD

 ::?(,		{"TZZL#%GJz"::>&-Yb$**q."1D0EQse#LJx }^,<HE<<H--/3&i(G7|q EFE B;

+K89E*<Me<T;UUVW
+K89E*<Me<T;UUVW ?j8"7^J7?
"7^J7?
%!$J!$JY'Qr
6234c
:,6KJ<WXY]^aXbbdef !  [^abjbvbv^wwxGr/   )r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r*   r   __static_attributes__ r/   r   r	   r	      s*     G1H6D$.# .r/   r	   )r   r   rI   r   r   r	   r`   r/   r   <module>ra      s<     # " 	i i  ir/   