-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
73 lines (65 loc) · 2.46 KB
/
server.py
File metadata and controls
73 lines (65 loc) · 2.46 KB
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
"""
Visa Bulletin Reader - Web Application using Flask to read and display the visa bulletin dates
for the specified visa type and country.
"""
from flask import Flask, render_template, request
from visabulletinreader import get_visa_options, read_bulletin_section, init_reader
app = Flask(__name__)
@app.route('/health', methods=['GET'])
def health():
"""
Quick health check page
"""
return "<b>Healthy</b><br/><h2>--Simple healthcheck page</h2>"
@app.route('/about')
def about():
"""
Renders the about page.
"""
return render_template('about.html')
@app.route('/references')
def references():
"""
Renders the references page.
"""
return render_template('references.html')
@app.route('/')
def index():
"""
Renders the index page with visa options.
:return: render_template: The index.html template with visa options.
"""
visa_types, visa_countries = get_visa_options()
bulletin_url, title = init_reader()
visa_dates = read_bulletin_section(bulletin_url, visa_types[0], visa_countries[0])
return render_template(
'index.html',
bulletin_url=bulletin_url,
bulletin_src=title,
visa_types=visa_types,
visa_countries=visa_countries,
headers=visa_dates.columns.tolist() if visa_dates is not None else [],
visa_dates=visa_dates.values.tolist() if visa_dates is not None else [])
@app.route('/', methods=['POST'])
def get_bulletin():
"""
Handles the form submission to get visa bulletin dates.
:return: render_template: The index.html template with visa dates.
"""
visa_type = request.form['visa_type']
visa_country = request.form['visa_country']
bulletin_url, title = init_reader()
visa_types, visa_countries = get_visa_options()
visa_dates = read_bulletin_section(bulletin_url, visa_type, visa_country)
print(visa_dates)
return render_template('index.html',
bulletin_url=bulletin_url,
bulletin_src=title,
visa_types=visa_types,
selected_visa_type=visa_type,
visa_countries=visa_countries,
selected_visa_country= visa_country,
headers = visa_dates.columns.tolist() if visa_dates is not None else [],
visa_dates=visa_dates.values.tolist() if visa_dates is not None else [])
if __name__ == "__main__":
app.run(debug=True)