-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
48 lines (36 loc) · 1.38 KB
/
Copy pathapplication.py
File metadata and controls
48 lines (36 loc) · 1.38 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
#!/usr/bin/env python3
"""
Author: donsky
For: www.donskytech.com
Purpose: Create a REST Server Interface using Bottle for future IOT Projects
"""
from bottle import route, run, request, get, response, default_app
from paste import httpserver
import sqlite3
import json
from pathlib import Path
# NOTE: CHANGE THIS TO WHERE YOU DOWNLOAD YOUR GIT REPO
db_folder = Path("C:/Users/Magnificent/PycharmProjects/database-project-master/StudentDB.db")
application = default_app()
@get('/student/isauthorized')
def message():
rf_id_code = request.query.rf_id_code.lstrip().rstrip()
length = len(rf_id_code)
print(f"Received the following query parameter rf_id_code={rf_id_code}, len={length}")
conn = sqlite3.connect(db_folder)
cursor = conn.cursor()
cursor.execute("SELECT COUNT(*) FROM STUDENTS WHERE RF_ID_CODE=?", (rf_id_code,))
result = cursor.fetchone()
row_count = result[0]
print(f"query result :: ", row_count);
cursor.close()
# Set Response Header to JSON
response.headers['Content-Type'] = 'application/json'
response.headers['Cache-Control'] = 'no-cache'
if (row_count > 0):
message_result = {"is_authorized": "true"}
else:
message_result = {"is_authorized": "false"}
print(f"message_result :: {message_result}")
return json.dumps(message_result)
httpserver.serve(application, host='0.0.0.0', port=8080)