<s> import logging <EOL> import requests <EOL> from datetime import datetime <EOL> from main . models import Station <EOL> import csv <EOL> def populate_stations ( path = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> reader = csv . reader ( f , delimiter = '<STR_LIT:U+002C>' ) <EOL> next ( reader , None ) <EOL> for row in reader : <EOL> obj , created = Station . objects . update_or_create ( <EOL> station_id = row [ <NUM_LIT:0> ] , defaults = { <EOL> '<STR_LIT:name>' : row [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : row [ <NUM_LIT:2> ] <EOL> } <EOL> ) <EOL> if created : <EOL> logging . info ( "<STR_LIT>" % row [ <NUM_LIT:0> ] ) <EOL> else : <EOL> logging . info ( "<STR_LIT>" % row [ <NUM_LIT:0> ] ) <EOL> def get_EFA_from_VVS ( station_id ) : <EOL> """<STR_LIT>""" <EOL> zocationServerActive = <NUM_LIT:1> <EOL> lsShowTrainsExplicit = <NUM_LIT:1> <EOL> stateless = <NUM_LIT:1> <EOL> language = '<STR_LIT>' <EOL> SpEncId = <NUM_LIT:0> <EOL> anySigWhenPerfectNoOtherMatches = <NUM_LIT:1> <EOL> limit = <NUM_LIT:30> <EOL> depArr = '<STR_LIT>' <EOL> type_dm = '<STR_LIT>' <EOL> anyObjFilter_dm = <NUM_LIT:2> <EOL> deleteAssignedStops = <NUM_LIT:1> <EOL> name_dm = station_id <EOL> mode = '<STR_LIT>' <EOL> dmLineSelectionAll = <NUM_LIT:1> <EOL> useRealtime = <NUM_LIT:1> <EOL> outputFormat = '<STR_LIT>' <EOL> coordOutputFormat = '<STR_LIT>' <EOL> url = '<STR_LIT>' <EOL> url += '<STR_LIT>' . format ( zocationServerActive ) <EOL> url += '<STR_LIT>' . format ( lsShowTrainsExplicit ) <EOL> url += '<STR_LIT>' . format ( stateless ) <EOL> url += '<STR_LIT>' . format ( language ) <EOL> url += '<STR_LIT>' . format ( SpEncId ) <EOL> url += '<STR_LIT>' . format ( <EOL> anySigWhenPerfectNoOtherMatches <EOL> ) <EOL> url += '<STR_LIT>' . format ( limit ) <EOL> url += '<STR_LIT>' . format ( depArr ) <EOL> url += '<STR_LIT>' . format ( type_dm ) <EOL> url += '<STR_LIT>' . format ( anyObjFilter_dm ) <EOL> url += '<STR_LIT>' . format ( deleteAssignedStops ) <EOL> url += '<STR_LIT>' . format ( name_dm ) <EOL> url += '<STR_LIT>' . format ( mode ) <EOL> url += '<STR_LIT>' . format ( dmLineSelectionAll ) <EOL> url += ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) . format ( <EOL> datetime . now ( ) ) <EOL> url += '<STR_LIT>' . format ( useRealtime ) <EOL> url += '<STR_LIT>' . format ( outputFormat ) <EOL> url += '<STR_LIT>' . format ( coordOutputFormat ) <EOL> r = requests . get ( url ) <EOL> r . encoding = '<STR_LIT>' <EOL> efa = r . json ( ) <EOL> return efa <EOL> def parse_efa ( efa ) : <EOL> parsedDepartures = [ ] <EOL> if not efa or "<STR_LIT>" not in efa or not efa [ "<STR_LIT>" ] : <EOL> return parsedDepartures <EOL> for departure in efa [ "<STR_LIT>" ] : <EOL> stopName = departure [ "<STR_LIT>" ] <EOL> latlon = departure [ '<STR_LIT:y>' ] + "<STR_LIT:U+002C>" + departure [ '<STR_LIT:x>' ] <EOL> number = departure [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> direction = departure [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" in departure : <EOL> realDateTime = departure [ "<STR_LIT>" ] <EOL> elif "<STR_LIT>" in departure : <EOL> realDateTime = departure [ "<STR_LIT>" ] <EOL> else : <EOL> realDateTime = None <EOL> if "<STR_LIT>" in departure and "<STR_LIT>" in departure [ "<STR_LIT>" ] : <EOL> delay = departure [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> else : <EOL> delay = <NUM_LIT:0> <EOL> departureObject = { <EOL> "<STR_LIT>" : stopName , <EOL> "<STR_LIT>" : number , <EOL> "<STR_LIT>" : direction , <EOL> "<STR_LIT>" : realDateTime , <EOL> "<STR_LIT>" : delay , <EOL> "<STR_LIT>" : latlon <EOL> } <EOL> parsedDepartures . append ( departureObject ) <EOL> return parsedDepartures </s>
