-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
app.py
98 lines (67 loc) · 2.81 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from flask import Flask, render_template, request, redirect
import datetime
import pytz # timezone
import requests
import os
app = Flask(__name__)
@app.route('/', methods=['GET'])
def home_page():
return render_template('index.html')
@app.route('/<name>')
def profile(name):
return render_template('index.html', name=name)
@app.route('/add_numbers', methods=['GET','POST'])
def add_numbers_post():
# --> ['5', '6', '8']
# print(type(request.form['text']))
if request.method == 'GET':
return render_template('add_numbers.html')
elif request.method == 'POST':
print(request.form['text'].split())
total = 0
try:
for str_num in request.form['text'].split():
total += int(str_num)
return render_template('add_numbers.html', result=str(total))
except ValueError:
return "Easy now! Let's keep it simple! 2 numbers with a space between them please"
@app.route('/shopping_list', methods=['GET','POST'])
def shopping_list_post():
# --> ['5', '6', '8']
# print(type(request.form['text']))
if request.method == 'GET':
return render_template('shopping_list.html')
elif request.method == 'POST':
print(request.form['text'].split())
shop_list = []
try:
for item in request.form['text'].split():
shop_list.append(item)
return render_template('shopping_list.html', result="\n".join([str(item) for item in shop_list]))
except ValueError:
return "Easy now! Let's keep it simple! Just words with a space between them"
@app.route('/time', methods=['GET','POST'])
def time_post():
# --> ['5', '6', '8']
# print(type(request.form['text']))
if request.method == 'GET':
return render_template('time.html')
elif request.method == 'POST':
print(request.form['text'].split())
for item in request.form['text'].split():
answer = (datetime.datetime.now(pytz.timezone("Europe/Dublin")).strftime('Time = ' + '%H:%M:%S' + ' GMT ' + ' Year = ' + '%d-%m-%Y'))
#answer = datetime.datetime.now().strftime('Time == ' + '%H:%M:%S' + ' Year == ' + '%d-%m-%Y')
#answer = datetime.datetime.now().strftime('%Y-%m-%d \n %H:%M:%S')
return render_template('time.html', result=answer)
@app.route('/python_apps')
def python_apps_page():
return render_template('python_apps.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/blog', methods=['GET'])
def blog_page():
return render_template('blog.html')
app.run(host=os.getenv('IP', '0.0.0.0'), port = int(os.getenv('PORT', 8080)))
if __name__ == '__main__':
app.run(debug=False)