-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
27 lines (24 loc) · 823 Bytes
/
backend.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
from flask import Flask
import json
import sqlite3
app = Flask(__name__)
#Given a bank branch IFSC code, get branch details
@app.route('/ifsc/<ifsc_code>')
def ifsc_get(ifsc_code):
conn = sqlite3.connect('bank.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM bank_branches where ifsc=?;", (ifsc_code,) )
branch = cursor.fetchall()
conn.commit()
return json.dumps(branch)
#Given a bank name and city, gets details of all branches of the bank in the city
@app.route('/bank_name/<bank_name>/city/<city>')
def branch_city_get(bank_name,city):
conn = sqlite3.connect('bank.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM bank_branches where bank_name=? and city=?;", (bank_name,city,) )
branches = cursor.fetchall()
conn.commit()
return json.dumps(branches)
if __name__=='__main__':
app.run()