So I'm currently making an application in Python that would show live departures and then show a countdown when there are 0 minutes to departure. What my issue is that I don't want to edit the code to change stops, I want to just be able to input the route_type and stop from the html formand then pass that via Flask to the API.
The API is the PTV Timetable API that includes real time departures. The API has a Swagger page so I know what to insert.
So what I've done is added the authentication code and then added the forms from bootstrap into the HTML file. I've tried googling the problem but I don't really know how the HTML forms can talk to flask so it can get added to the API. Thanks
Python Code
def getUrl(request):
DevId = <ID>
apikey = <KEY>
request = request + ('&') if ('?' in request) else '?')
raw = 'request' +'DevId={0}'.format(DevId)
hashkey = hmac.new(key, raw, sha1)
signature = hashkey.hexdigest()
return ''https://timetableapi.ptv.vic.gov.au'+raw+'&signature={1}'.format(devId, signature)
from_zone = tz.gettz('UTC')
to_zone = tz.gettz ('Australia/Melbourne')
#get next departures
url = getUrl('/v3/departures/route_type/{route_type}/stop/{stop_id}')
@app.route('/')
@app.route('home')
def home():
return flask.render_template('home.html')
HTML Code
<body>
<form>
<div class="form-group">
<label for="station-id-input">Station ID</label>
<input type="text" class="form-control" placeholder="Station ID">
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inline-train" value="route_type0">
<label class="form-check-label" for="inline-train">Train</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inline-tram" value="route_type1">
<label class="form-check-label" for="inline-train">Tram</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inline-bus" value="route_type2">
<label class="form-check-label" for="inline-train">Bus</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inline-vline" value="route_type3">
<label class="form-check-label" for="inline-train">V/Line</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inline-nightbus" value="route_type4" disabled>
<label class="form-check-label" for="inline-train"Night Bus (Not Implemented)</label>
</div>
</body>