-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
278 lines (206 loc) Β· 9.97 KB
/
main.py
File metadata and controls
278 lines (206 loc) Β· 9.97 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
from flask import Flask, request, jsonify
from flask_cors import CORS
from studentvue import StudentVue
import traceback
app = Flask(__name__)
CORS(app)
def create_studentvue_client(username, password, district_url):
# creates studentvue client with creds
try:
return StudentVue(username, password, district_url)
except Exception as e:
raise Exception(f"Cannot authenticate with StudentVue, error: {str(e)}")
def validate_auth_params(data):
required_params = ['username', 'password', 'district_url']
missing_params = [param for param in required_params if param not in data]
if missing_params:
return False, f"Missing required parameters! Missing: {', '.join(missing_params)}"
return True, None
@app.route('/health', methods=['GET'])
def health_check():
return jsonify({"status": "healthy", "message": "success! APIVUE is running successfully"})
@app.route('/student_info', methods=['POST'])
def get_student_info():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
student_info = sv.get_student_info()
return jsonify({"success": True, "data": student_info})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/school_info', methods=['POST'])
def get_school_info():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
school_info = sv.get_school_info()
return jsonify({"success": True, "data": school_info})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/attendance', methods=['POST'])
def get_attendance():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
attendance = sv.get_attendance()
return jsonify({"success": True, "data": attendance})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/calendar', methods=['POST'])
def get_calendar():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
calendar = sv.get_calendar()
return jsonify({"success": True, "data": calendar})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/class_notes', methods=['POST'])
def get_class_notes():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
class_notes = sv.get_class_notes()
return jsonify({"success": True, "data": class_notes})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/gradebook', methods=['POST'])
def get_gradebook():
"""Get student's gradebook"""
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
report_period = data.get('report_period', 0)
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
gradebook = sv.get_gradebook(report_period)
return jsonify({"success": True, "data": gradebook})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/schedule', methods=['POST'])
def get_schedule():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
term_index = data.get('term_index', 0)
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
schedule = sv.get_schedule(term_index)
return jsonify({"success": True, "data": schedule})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/messages', methods=['POST'])
def get_messages():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
messages = sv.get_messages()
return jsonify({"success": True, "data": messages})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/documents', methods=['POST'])
def list_documents():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
documents = sv.list_documents()
return jsonify({"success": True, "data": documents})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/document', methods=['POST'])
def get_document():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
if 'document_guid' not in data:
return jsonify({"error": "Missing required parameter: document_guid"}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
document = sv.get_document(data['document_guid'])
return jsonify({"success": True, "data": document})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/report_cards', methods=['POST'])
def list_report_cards():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
report_cards = sv.list_report_cards()
return jsonify({"success": True, "data": report_cards})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/report_card', methods=['POST'])
def get_report_card():
try:
data = request.get_json()
is_valid, error_msg = validate_auth_params(data)
if not is_valid:
return jsonify({"error": error_msg}), 400
if 'document_guid' not in data:
return jsonify({"error": "Missing required parameter: document_guid"}), 400
sv = create_studentvue_client(data['username'], data['password'], data['district_url'])
report_card = sv.get_report_card(data['document_guid'])
return jsonify({"success": True, "data": report_card})
except Exception as e:
return jsonify({"error": str(e), "traceback": traceback.format_exc()}), 500
@app.route('/', methods=['GET'])
def api_documentation():
endpoints = {
"health": "GET /health - Health check",
"student_info": "POST /student_info - Get student information",
"school_info": "POST /school_info - Get school information",
"attendance": "POST /attendance - Get attendance records",
"calendar": "POST /calendar - Get assignments/events calendar",
"class_notes": "POST /class_notes - Get class notes",
"gradebook": "POST /gradebook - Get gradebook (optional: report_period)",
"schedule": "POST /schedule - Get schedule (optional: term_index)",
"messages": "POST /messages - Get messages",
"documents": "POST /documents - List documents",
"document": "POST /document - Get specific document (requires: document_guid)",
"report_cards": "POST /report_cards - List report cards",
"report_card": "POST /report_card - Get specific report card (requires: document_guid)"
}
return jsonify({
"message": "StudentVUE Rest API",
"endpoints": endpoints,
"required_params": {
"username": "Student's username",
"password": "Student's password",
"district_url": "District domain URL"
},
"example_request": {
"username": "your_username",
"password": "your_password",
"district_url": "https://district.edupoint.com"
},
"info": "This API is under Apache License 2.0 and is provided as-is. Use at your own risk. Made by @aramshiva on github. The code is opensource at https://github.com/StudentVue/api. Thanks for using APIVUE!",
})
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=3000)