o
    liF	                     @   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}z,t|}|d }i }|D ]}|d	 d
 }|d d }|tj| |  |< |||< q#|W S  tyY }	 zt	d|	 W Y d }	~	d S d }	~	ww )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"   ]C:\Users\computer\Desktop\notes\tskylt4.0\server\20260117 - seems ok - no SNCB\netherlands.py	ns_lookup   s    

& r$   c                 C   s   d|  }t j|ddddj}t|}|d d }g }|D ]7}|d }|d	 d d
 }	z
|d d d }
W n   d}
Y |d }d}|d|	|
|dg d}|sU|| qt|rm|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   0	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   s0   
"r@   )r   )r   r5   r   r   r$   r@   r"   r"   r"   r#   <module>   s
    
