
    Mg                          S SK r S SKJr  S SKJrJr  S SKJr  SrSrS\0rS r	\" S	S
9\" S5       " S S5      5       5       r
g)    N)Fore)pluginrequire)tabulate 1ebd3b92bf5041249f8c1e7a540ce98cz https://api.football-data.org/v2zX-Auth-Tokenc                     [         R                  " [        U -   [        S9nUR	                  5       nSUR                  5       ;   a  g U$ )Nheaders	errorCode)requestsgeturlr
   jsonkeys)routers     >/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/football.pyfetchr      s7    S5['2A	AaffhH    T)networkfootballc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)Football   zy
Provides football competition information (tournament/league standings) and daily match info.

Enter 'football' to use.
c                     [        S5        U R                  U5      nUc  g U R                  U5      nUc  g US:X  a  U R                  X5        OUS:X  a  U R	                  X5        [        5         g )Nz4Football data provided by the Football-Data.org API
competitionsmatches)print
get_optionget_competitioncompetitionr   )selfjarvissoptioncompIds        r   __call__Football.__call__   sj    EF(> %%f->^#V,y LL(r   c                    SSS.nUR                  S[        R                  5        [        5         [        S5        [        S5        [        S5        [        5           [	        UR                  S[        R                  5      5      nUS	:X  a  g
US:X  d  US:X  a  X#   $ UR                  S[        R                  5         [        5         Mn  ! [         a#    UR                  S[        R                  5         N8f = f)zD
Get user input for choosing between
match info or competition info
r   r   )      zWhat information do you want:z1: Competition/league standingsz2: Today's matchesz3: ExitEnter your choice:    Nr*   r+   8Invalid input! Enter a number from the choices provided.)	sayr   BLUEr   intinputGREENYELLOW
ValueError)r"   r#   optionsr%   s       r   r   Football.get_option0   s    
 %3

2DII>/0"#i]V\\*?LMQ;q[FaK"?*JJRTXT_T_a
 G   ]

NPTP[P[]]s   /C
 C
  C
 
*C76C7c           	         UR                  S5        [        S5      nUc!  UR                  S[        R                  5        gUS   nUR                  S[        R
                  5        [        5         [        US   5       H/  n[        SR                  US	-   X4   S
   X4   S   S
   5      5        M1     [        S5        [        5           [        UR                  S[        R
                  5      5      nUS:X  a  gU[        S	US   S	-   5      ;   a
  X5S	-
     S   $ UR                  S[        R                  5         [        5         M~  ! [         a#    UR                  S[        R                  5         N8f = f)z3
Takes input from user for selecting a competition
	Fetching z/competitions?plan=TIER_ONEN)Error in fetching data - try again later.r   zPick a competition:countz
{}: {}, {}r*   nameareaz0: Exitr,   r   idr.   )spinner_startr   spinner_stopr   r4   r0   r   rangeformatr1   r2   r/   r5   )r"   r#   r   compsir%   s         r   r    Football.get_competitionL   s\   
 	[)/09 KT[[Y.!1499=qz"A,%%Aux'&)9&)AC D # 	i]V\\*?KLQ;uQ'
Q77 !,T22JJRTXT_T_a
 G   ]

NPTP[P[]]s   /E 8E  E *E21E2c                     UR                  S5        [        SR                  U5      5      nUc!  UR                  S[        R
                  5        gUR                  S5        [        5         U R                  XS   5        g)zR
Fetches details of a competition and outputs
the competition's current standings
r9   z/competitions/{}/standingsNr:    	standings)r?   r   rB   r@   r   r4   r   printStandings)r"   r#   r&   r   s       r   r!   Football.competitiono   sj     	[).55f=>9 KT[[YBFkN3r   c           	      n   [        U5      S:X  a!  UR                  S[        R                  5        gUS   S   c  UR                  SR	                  US   S   S   S   S   5      5        UR                  S	R	                  US   S   S
   S   S   5      5        UR                  SR	                  US   S   S   S   S   5      5        [        5         UR                  S[        R                  5        [        5         U H  nUS   S:w  a  M  US   b@  [        [        R                  S-   US   S   -   [        R                  -   5        [        5         / nUS    H2  nUS   S   US'   UR                  U Vs/ s H  oeU   PM	     sn5        M4     [        [        U/ SQS95        [        5         M     gs  snf )zM
Helper function for validating, formatting
and printing the standings table
r   z(No standings found for this competition.NgroupzFirst position:  {}tableteamr<   zSecond position: {}r*   zThird position:  {}r+   zHere are the full standings: typeTOTALzGROUP    )
#TeamPWDLPointsGFGAGDr	   )	lenr/   r   r0   rB   r   RESETappendr   )r"   r#   tablesrM   stListrN   ks          r   rI   Football.printStandings   s   
 v;!JJA499M!9W%JJ,33q	'"1%f-f57 8JJ,33q	'"1%f-f57 8JJ,33q	'"1%f-f57 8G

2DII>EV}'W~)dii(*U7^A->>KLFg#F|F3V51Aw56 '
 (6 ,M N OG#  6s   5F2c                    [        5         UR                  S5        [        SR                  U5      5      nUc!  UR	                  S[
        R                  5        gUR	                  S5        US   S:X  a!  UR                  S[
        R                  5        gUS	    Hl  nU R                  U5      n[        U5      nUR                  US   [
        R                  5        [        S
U5       H  n[        XW   5        M     [        5         Mn     g)zH
Fetches today's matches in given competition
and prints the match info
r9   z/matches?competitions={}Nr:   rG   r;   r   zNo matches found for today.r   r*   )r   r?   r   rB   r@   r   r4   r/   r0   formatMatchInfor\   rA   )r"   r#   r&   r   match	matchInfolengthrD   s           r   r   Football.matches   s    
 	[),33F;<9 KT[[YBW:?JJ4dii@ 9 007	Y

9Q<3q&)A),' * &r   c                    / nUS   S   R                  5       nUS   S   R                  5       nUR                  SR                  X45      5        US   nUS   nUR                  SR                  U5      5        UR                  SR                  UR                  5       5      5        US	:w  a  US
   nUS   S   nUS   S   n	UR                  SR                  X5      5        US   S   b0  US   S   n
US   S   nUR                  SR                  X5      5        US   S   b0  US   S   nUS   S   nUR                  SR                  X5      5        U$ )z8
Helper function for formatting
and printing match info
homeTeamr<   awayTeamz{} vs {}rL   statusz
Group:  {}z
Status: {}	SCHEDULEDscorefullTimezSCORE: {} - {}	extraTimezExtra time: {} - {}	penaltieszPenalties: {} - {})upperr^   rB   
capitalize)r"   re   linesrj   rk   rL   rl   scores	homeScore	awayScore	homeExtra	awayExtrahomePenawayPens                 r   rd   Football.formatMatchInfo   st   
 $V,224$V,224Z&&x:;gx\((/0\(():):)<=>[ 7^Fz*:6Iz*:6ILL)00FGk":.:";/
;	";/
;	)00FHk":.: -j9 -j9188JKr    N)__name__
__module____qualname____firstlineno____doc__r'   r   r    r!   rI   r   rd   __static_attributes__r}   r   r   r   r      s,    &8!F4 &P4"r   r   )r   coloramar   r   r   r   API_KEYr   r
   r   r   r}   r   r   <module>r      sX      " 
,(7
# 	
M M  Mr   