This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
49 lines (41 loc) · 1.45 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
"""
Created on June 18 2021
@author: Akhilesh Thite
"""
# Importing necessary libraries.
from flask import Flask, json, render_template, request
import requests
# To dispay json {{output}} in tables.
import json2table
# Defining Flask app.
app = Flask(__name__)
# Main page
@app.route('/')
def home():
return render_template('index.html')
# Search API
@app.route("/search", methods=["POST", "GET"])
def search():
if request.method == 'POST':
pincode = request.form["pincode"]
date = request.form["date"]
url = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?pincode={pincode}&date={date}"
response = requests.get(url).json()
build_direction = "TOP_TO_BOTTOM"
table_attributes = {"style": "width:50%"}
if response["sessions"] == []:
error = "Sessions are currently unavailable, please try again after some time."
return render_template('result.html', output=error)
else:
return render_template('result.html', output=json2table.convert(response, build_direction=build_direction,
table_attributes=table_attributes))
# Breathing page
@app.route('/breathing')
def breathing():
return render_template('breathing.html')
# Feedback page
@app.route('/feedback')
def feedback():
return render_template('feedback.html')
if __name__ == "__main__":
app.run(debug=True)