o
    g/h                     @   sp   d dl Z d dlZd dlZdd Zdd Zdd Zdd	 ZdddZdd Zdd Z	dd Z
edkr6e
  dS dS )    Nc                  C   s:   t d} | jdkrtdt| j | j}t|}|S )z: Retrieve the fpl player data from the hard-coded url
    z7https://fantasy.premierleague.com/api/bootstrap-static/   Response was code )requestsgetstatus_code	Exceptionstrtextjsonloads)responseresponseStrdata r   5/var/www/html/fpl_model_app/scripts/utills/getters.pyget_data   s   


r   c                 C   v   d}|t |  d }d}|dkr%zt|}W n	   td Y |dks|jdkr3tdt |j t|j	}|S )z Retrieve the player-specific detailed data

    Args:
        player_id (int): ID of the player whose data is to be retrieved
    z6https://fantasy.premierleague.com/api/element-summary//    r   r   
r   r   r   timesleepr   r   r
   r   r	   )	player_idbase_urlfull_urlr   r   r   r   r   get_individual_player_data      
r   c                 C   r   ) Retrieve the summary/history data for a specific entry/team

    Args:
        entry_id (int) : ID of the team whose data is to be retrieved
    ,https://fantasy.premierleague.com/api/entry/z	/history/r   r   r   r   r   entry_idr   r   r   r   r   r   r   get_entry_data"   r   r"   c                 C   r   )r   r   r   r   r   r   r   r   r    r   r   r   get_entry_personal_data5   r   r#      c           	      C   s   d}g }t ||d D ]D}|t|  d t| d }d}|dkr6zt|}W n	   td Y |dks!|jdkrDtdt|j t	|j
}||g7 }q|S )	z Retrieve the gw-by-gw data for a specific entry/team

    Args:
        entry_id (int) : ID of the team whose data is to be retrieved
    r   r$   z/event/z/picks/r   r   r   r   )ranger   r   r   r   r   r   r   r
   r   r	   )	r!   num_gwsstart_gwr   gw_datair   r   r   r   r   r   get_entry_gws_dataH   s    
r*   c                 C   r   )z Retrieve the transfer data for a specific entry/team

    Args:
        entry_id (int) : ID of the team whose data is to be retrieved
    r   z/transfers/r   r   r   r   r   r    r   r   r   get_entry_transfers_data^   r   r+   c                  C   sf   d} d}|dkrzt | }W n	   td Y |dks|jdkr+tdt|j t|j	}|S )z/ Retrieve the fixtures data for the season
    z/https://fantasy.premierleague.com/api/fixtures/r   r   r   r   )
r   r   r   r   r   r   r   r
   r   r	   )urlr   r   r   r   r   get_fixtures_dataq   s   
r-   c                  C   sB   t  } tdd}t| | W d    d S 1 sw   Y  d S )Nzraw.jsonw)r   openr
   dump)r   outfr   r   r   main   s   "r2   __main__)r$   )r   r
   r   r   r   r"   r#   r*   r+   r-   r2   __name__r   r   r   r   <module>   s    


