a
    ki)                     @   s$   d dl Z d dl T dd Zdd ZdS )    N)*c              	      s`  dd l }dd l dd l}dd l}d| d }dddd}d}|j|||d	|id
}	|	j}
||
}g } fdd}|d d d }|D ]}|d d }|d d d d dd }|d d d d }|d d d }t	|||| |d|||
 ddddd dd!d"d#g d$}|| qt	| t|r\|tj|  | | d%< |S d S )&Nr   z
    {
    stopPlace(id: "ar  ") {
        id
        name
        estimatedCalls(numberOfDepartures: 40) {     
        realtime
        aimedArrivalTime
        aimedDepartureTime
        expectedArrivalTime
        expectedDepartureTime
        actualArrivalTime
        actualDepartureTime
        date
        forBoarding
        forAlighting
        destinationDisplay {
            frontText
        }
        quay {
            id
        }
        serviceJourney {
            journeyPattern {
            line {
                id
                name
                transportMode
            }
            }
        }
        }
    }
    }
    zno-cachezapplication/jsonzdeparture-board)zCache-ControlzContent-TypeZTskyltz/https://api.entur.io/journey-planner/v3/graphqlquery)headersdatac                    sF    j  j  dd}| j| d }| jdd8 }|dS )Nr   )seconds   )hoursz%Y-%m-%dT%H:%M:%S)datetimecombinedatetodaytime	timedeltastrftime)r   midnightresultr	    /var/www/html/norway.pyconvert_seconds_to_datetime<   s    z7no_load_departures.<locals>.convert_seconds_to_datetimer   Z	stopPlaceZestimatedCallsZdestinationDisplayZ	frontTextserviceJourneyZjourneyPatternlineidzLine:r   transportModeZexpectedDepartureTime   0RAILTRAINZWATERFERRYZFLYTOGZFLYBUSSBUS)r   transport_mode)destinationdirection_codeexpectedr   
deviations
departures)requestsr	   urllib.requestjsonpostdumpstextloadssplitprintupperreplaceappendlenv	operators)countryoperatorstationr&   urllibr(   r   hdrurlresponseoutxresultsr   r%   namer   t_type_time
new_recordr   r   r   no_load_departures   sH    %
,
rC   c                 C   s   dd l }dd l}d| }||}|j}||}|d }i }	|D ]r}
d|
d d v rB|
d d }|
d d }|
d d }z$||	v rt|d	 | }t| W n   Y n0 ||	|< qB|	S )
Nr   z3https://api.entur.io/geocoder/v1/autocomplete?text=featuresz:StopPlace:Z
propertiesr   Zcountyr?    )r&   r(   getr+   r,   strr.   )r5   r6   r7   r&   r(   r:   r;   r<   r=   search_listir   Zkommunr?   r   r   r   	no_lookuph   s(    


rJ   )r3   rC   rJ   r   r   r   r   <module>   s   d