
    Mg                     t    S SK r S SKJrJr  S SKJr  S SKJr  Sr\" SS9\" S5       " S	 S5      5       5       rg)
    N)pluginrequire)Fore)Memoryz6https://api.sportradar.com/tennis/trial/v3/en/rankingsT)networktennisc                   T    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)r   	   zk
Tennis Plugin for getting information about ATP and
!!! needs api.sportradar.com/tennis API_KEY for usage
c                     [        S5        U R                  U5         U R                  U5      nUc  g U R                  X5        M(  )Nz+
Tennis data provided by the sportradar.com)printget_api_key
get_optionprocess_option)selfjarvissoptions       </Users/admin/workspace/ai/Jarvis/jarviscli/plugins/tennis.py__call__tennis.__call__   sE    <= __V,F~/	     c                    U R                  SU R                   35      nUc!  UR                  S[        R                  5        gUS:X  a  U R                  U5        US:X  a  U R                  U5        US:X  a  U R                  U5        gg)z
Processes the users input option and performs required action,
either getting and printing ATP rankings,
getting and printing WTA rankings, or resetting API key
z	?api_key=Nz+Error While Loading Data - Try Again Later.atpwtanew_key)
fetch_datakeyspinner_stopr   YELLOWget_atp_top10get_wta_top10update_api_key)r   r   r   datas       r   r   tennis.process_option   s     488*56< !348KKAU?t$U?t$Y' r   c                     US   S   S   nU Vs/ s H
  o3S   S   PM     nnSn[        S5        USS	  H  n[        U S
U 35        US-  nM     gs  snf )z?
Makes API call to get ATP rankings, prints out top 10 players
rankingsr   competitor_rankings
competitorname   z
Current ATP Rankings
N
   . r   )r   r#   atp_rankingsobj	atp_namesir)   s          r   r    tennis.get_atp_top10,   st     J'*+@A:FG,3&v.,	G()crNDQCr$.!FA # H   Ac                     US   S   S   nU Vs/ s H
  o3S   S   PM     nnSn[        S5        USS  H  n[        U S	U 35        US-  nM     gs  snf )
z?
Makes API call to get WTA rankings, prints out top 10 players
r&   r*   r'   r(   r)   z
Current WTA Rankings:
Nr+   r,   r-   )r   r#   wta_rankingsr/   	wta_namesr1   r)   s          r   r!   tennis.get_wta_top108   st     J'*+@A:FG,3&v.,	G)*crNDQCr$.!FA # Hr3   c                 
    SS0$ )zA
Gets headers required for all HTTP requests made by this plugin
acceptzapplication/json )r   s    r   get_headerstennis.get_headersD   s     ,--r   c                     [         R                  " [        U-   U R                  5       S9nUR	                  5       nSUR                  5       ;   a  gU$ )z 
Makes API call for given route
)headers	errorCodeN)requestsgetURLr;   jsonkeys)r   routers      r   r   tennis.fetch_dataJ   sB     LLud.>.>.@AFFH!&&("r   c                     [        S5      nUR                  S5      cI  UR                  S[        R                  5      nUR                  SU5        UR                  5         X0l        gUR                  S5      U l        g)zo
Either gets API key from memory or, if one is not there,
asks the user for an API key and stores it in memory
tennis.jsonAPI_KEYNz)Enter api.sportradar.com/tennis API_KEY: )r   get_datainputr   GREENadd_datasaver   )r   r   muser_api_keys       r   r   tennis.get_api_keyT   sd    
 =!::i (!<< )459ZZALJJy,/FFH#Hzz),DHr   c                     UR                  S[        R                  5      n[        S5      nUR	                  SU5        UR                  5         X l        g)zC
Prompts user to enter a new API key and stores this key in memory
z-Enter New api.sportradar.com/tennis API_KEY: rI   rJ   N)rL   r   rM   r   update_datarO   r   )r   r   rQ   rP   s       r   r"   tennis.update_api_keyc   sD     || %015==!	i.	r   c                    SSSS.n[        5         UR                  S[        R                  5        [        5         [        S5        [        S5        [        S5        [        S	5        [        5         U R	                  U5      nUS
:X  a  gX#   $ )zr
Prompts user for what feature of the tennis plugin they'd like
to use and takes in and returns the user's choice
r   r   r   r*         zHow Can I Help You?z!1: Get ATP (mens) tennis rankingsz#2: Get WTA (womens) tennis rankingsz3: Insert new API_KEYz4: exitN)r   sayr   BLUE
get_choice)r   r   optionschoices       r   r   tennis.get_optionn   su    
 )4

($))41234%&i(R<?"r   c                 0     [        UR                  S[        R                  5      5      nUS:X  a  gUS;   a  U$ UR	                  S[        R
                  5         [        5         Mf  ! [         a#    UR	                  S[        R
                  5         N8f = f)zq
Prompts user for integer choice indicating what part of the
tennis plugin they want to use, returns this choice
zEnter your choice:    rZ   rW   z8Invalid input! Enter a number from the choices provided.)intrL   r   rM   r[   r   
ValueErrorr   )r   r   inserted_values      r   r]   tennis.get_choice   s    
 ?!$V\\ 3=>Bjj&J "K!Q&#y0))JJ56:kkC G!   ?

126++??s   /A( A(  A( (*BB)r   N)__name__
__module____qualname____firstlineno____doc__r   r   r    r!   r;   r   r   r"   r   r]   __static_attributes__r:   r   r   r   r   	   s9    
0($

.-	 #*r   )	r@   r   r   coloramar   packages.memory.memoryr   rB   r   r:   r   r   <module>ro      sD     "  )> 	M M  Mr   