-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
54 lines (47 loc) · 1.68 KB
/
api.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
from flask import Flask, request, jsonify,make_response
from pwMod import fetch_att
import time
app = Flask(__name__)
MAX_RETRIES = 3
RETRY_DELAY = 1
@app.route('/')
def index():
html_content = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<style>
/* Optional: Additional custom styles */
</style>
</head>
<body class="bg-gray-100 h-full w-full flex flex-col items-center justify-center text-gray-900 font-sans">
<h1 class="font-bold">OnlyVels Attendence Api Endpoint</h1>
<h3>/attendance?username=YourRegNo&password=YourPassword</h3>
</body>
</html>
'''
return make_response(html_content)
@app.route('/attendance', methods=['GET'])
def get_attendance():
username = request.args.get('username')
password = request.args.get('password')
if not username or not password:
return jsonify({'error': 'Username and password are required'}), 400
attempt = 0
while attempt < MAX_RETRIES:
try:
student_name, percentage, end_date = fetch_att(username, password)
return jsonify({'student_name': student_name, 'percentage': percentage, 'Last Updated': end_date})
except Exception as e:
attempt += 1
if attempt < MAX_RETRIES:
time.sleep(RETRY_DELAY)
else:
return jsonify({'error': str(e)}), 500
return jsonify({'error': 'Unexpected error'}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0',port=3001)