a
    ki	                     @   s@   d dl Z d dlZd dlZd dlZd dlT dddZd	ddZdS )
    N)*nlc           
   
   C   s   | dd}d| }tj|ddddj}zXt|}|d }i }|D ]6}|d	 d
 }|d d }|tj| |  |< |||< qF|W S  ty }	 zt	d|	 W Y d }	~	n
d }	~	0 0 d S )N z%20z4https://gateway.apiportal.ns.nl/nsapp-stations/v3?q=
text/plain 84bde7f6d3f94893a31eb6ef63a0cef0acceptzOcp-Apim-Subscription-KeyheaderspayloadidZuicCodenamesZmediumzError: )
replacerequestsgettextjsonloadsvsites	Exceptionprint)
operatorstationcountryurldatasearch_liststationssiteidnamee r"   /var/www/html/netherlands.py	ns_lookup   s    

r$   c                 C   s   d|  }t j|ddddj}t|}|d d }g }|D ]r}|d }|d	 d d
 }	z|d d d }
W n   d}
Y n0 |d }d}|d|	|
|dg d}|s<|| q<t|r|tt	 dt
j| | | < |S d S )Nz[https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/departures?lang=english&&uicCode=r   r   r   r	   r   
departures	directionZactualDateTime   ZplannedTrack   0Z	cancelledTRAIN)r   transport_mode)destinationdirection_codeexpectedline
deviations)r%   	timestamp)r   r   r   r   r   appendlentimemktime	localtimer   	operators)r   r   r   r   responser%   resultsir,   _time__line	_canceledr+   departures_dictr"   r"   r#   ns_load_departures   s,    
"r?   )r   )r   )r   r4   r   r   r$   r?   r"   r"   r"   r#   <module>   s   
