-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.py
35 lines (27 loc) · 1.54 KB
/
webapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import flask, datetime, sqlite3, getjourneys, cli
app = flask.Flask(__name__)
@app.route("/")
def login():
return flask.render_template('login.html', current_month=datetime.datetime.today().strftime("%Y-%m"))
@app.route("/journeys", methods=['POST'])
def show_journey_page():
year, month=flask.request.form["month"].split("-")
journeydata=getjourneys.grabJourneys(int(year), int(month), flask.request.form["username"], flask.request.form["password"])
journeys = []
totalcost=0
for t in journeydata:
for transaction in t["transactions"]:
for ticket in transaction["journeyPattern"]["tickets"]:
# Filter by station if specified in args
if 'filter' in globals():
if ticket["destinationName"] == filter:
price = cli.convertFare(ticket["fare"])
totalcost = totalcost + price
journeys.append(str(t["date"]) + "\n" + (ticket["originName"] + " to " + ticket["destinationName"]) + str(ticket["description"].title()) + "\n" + str(("£%.2f"%price)))
else:
price = cli.convertFare(ticket["fare"])
totalcost = totalcost + price
journeys.append(str(t["date"]) + "\n" + (ticket["originName"] + " to " + ticket["destinationName"]) + str(ticket["description"].title()) + "\n" + str(("£%.2f"%price)))
return flask.render_template('main.html', journeys=journeys, total=totalcost)
if __name__ == "__main__":
app.run(host='0.0.0.0')