更新 views.py
parent
c7024d5851
commit
d41e846ee4
51
app/views.py
51
app/views.py
|
|
@ -1,8 +1,9 @@
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import openpyxl as openpyxl
|
import openpyxl as openpyxl
|
||||||
from flask import Flask, redirect, url_for, render_template, session, jsonify, request, send_file
|
from flask import Flask, redirect, url_for, render_template, session, jsonify, request, send_file
|
||||||
|
from utils.time_utils import check_now_time
|
||||||
from utils.allowed_files import allowed_excel
|
from utils.allowed_files import allowed_excel
|
||||||
from db.connection import MySQLPool
|
from db.connection import MySQLPool
|
||||||
from config import SECRET_KEY
|
from config import SECRET_KEY
|
||||||
|
|
@ -291,5 +292,53 @@ def receive_excel():
|
||||||
return jsonify({"error": "Invalid file type"}), 400
|
return jsonify({"error": "Invalid file type"}), 400
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/get-course-name', methods=['GET'])
|
||||||
|
def get_course_name():
|
||||||
|
data = {'course_name': "信息技术"}
|
||||||
|
return jsonify({
|
||||||
|
'msg': 'ok',
|
||||||
|
'data': data
|
||||||
|
})
|
||||||
|
period_id, period_name = check_now_time() # 获取当前时间段信息
|
||||||
|
print(f"period_id: {period_id}, period_name: {period_name}")
|
||||||
|
|
||||||
|
# 如果当前不在任何时间段内
|
||||||
|
if period_id is None:
|
||||||
|
return jsonify({
|
||||||
|
'msg': period_name, # 返回不在课程时间段内的消息
|
||||||
|
'data': None
|
||||||
|
})
|
||||||
|
|
||||||
|
# 获取当前用户编号
|
||||||
|
number = session.get('number')
|
||||||
|
if not number:
|
||||||
|
return jsonify({"msg": "用户未登录或编号不可用", "data": None})
|
||||||
|
|
||||||
|
# 获取今天是星期几
|
||||||
|
day_of_week = datetime.date.today().weekday() + 1
|
||||||
|
|
||||||
|
# 如果是周末
|
||||||
|
if not (1 <= day_of_week <= 5):
|
||||||
|
return jsonify({"msg": "周末没有课程", "data": None})
|
||||||
|
|
||||||
|
# 如果是工作日,获取课程信息
|
||||||
|
print(f"day of week: {day_of_week}")
|
||||||
|
db_manager = DatabaseManager()
|
||||||
|
data = db_manager.get_course_name(number, day_of_week)
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
# 返回课程信息
|
||||||
|
return jsonify({
|
||||||
|
'msg': 'ok',
|
||||||
|
'data': data
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/student-sign-in', methods=['POST'])
|
||||||
|
def student_sign_in():
|
||||||
|
number = session.get("number")
|
||||||
|
print(number)
|
||||||
|
return "aaa"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
||||||
Reference in New Issue