-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgped.py
39 lines (33 loc) · 1.27 KB
/
gped.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
36
37
38
39
from flask import Flask, render_template, request, redirect, flash, url_for
from datetime import date
from relativespeedsite.forms import SingleFieldDateForm
from relativespeedsite.functions import calculate_facts
import chronyk
app = Flask(__name__)
app.config.update(WTF_CSRF_ENABLED=True,
SECRET_KEY="lol")
@app.route('/', methods=['GET', 'POST'])
def index():
form = SingleFieldDateForm()
if request.method == "POST" and not form.birth_date.errors:
try:
print(form.birth_date)
birthdate = chronyk.Chronyk(form.birth_date.data.replace(". ", " "), allowfuture=False)
except chronyk.DateRangeError:
flash("Greetings, time-traveler... Maybe try something more realistic this time.")
return render_template("index.html", form=form)
except ValueError:
flash("Sorry, I couldn't parse that. Try rephrasing?")
return render_template("index.html", form=form)
birthdate = date.fromtimestamp(birthdate.timestamp())
facts = calculate_facts(birthdate)
print(facts)
return render_template("index.html", facts=facts, form=form)
elif form.birth_date.errors:
flash(form.birth_date.errors[0])
return render_template("index.html", form=form)
else:
print("I failed")
return render_template("index.html", form=form)
if __name__ == '__main__':
app.run()