You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.5 KiB

4 months ago
import requests
import time
import json
import random
import cProfile
from test.test_all import response_call
def getinformation_t (url,class_name,file_path):
with open(file_path, 'rb') as f:
file = {'file': f}
data = {'class_name': class_name}
response = requests.post(url, files=file, data=data)
print(response.text)
def call_students_t (url,data_call):
response_call = requests.post(url, data=data_call)
print(response_call.text)
return response_call
def updatetable_t (url,data_update):
response_update = requests.post(url, data=data_update)
print(response_update.text)
def show_information_t (url,data_show):
response_show = requests.post(url, data=data_show)
print(response_show.text)
def main ():
#一、导入2个班级
url = 'http://127.0.0.1:8000/get/information/'
class_name1 = '嵌入式系统'
file_path1 = 'C:/Users/Lenovo/Desktop/嵌入式系统.xlsx'
getinformation_t(url,class_name1,file_path1)
class_name2 = '软件工程'
file_path2 = 'C:/Users/Lenovo/Desktop/软工学生名单.xlsx'
getinformation_t(url,class_name2,file_path2)
#课前点名举例3个
url_call = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确
data_call = {
'class_name': '软件工程',
'num': 3,
'mode': 1 # 点名使用正常模式
}
response_call = call_students_t(url_call,data_call)
res = response_call.json()
result = res.get('result', {})
url_update = 'http://127.0.0.1:8000/update/table/'
# 有到加1分没到扣一分
for name, student_id in result.items():
print(student_id)
point = random.choice([1, -1])
data_update = {
'point': point,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
updatetable_t(url_update,data_update)
# 三、上课提问,一个一个提问,问了之后直接加分,选择三五成群的模式提问完直接加分提问3次
i = 0
while i < 3:
data_call = {
'class_name': '软件工程',
'num': 1,
'mode': 3
}
response_call1 = call_students_t(url_call, data_call)
res = response_call1.json()
result = res.get('result', {})
student_ids = list(result.values())
if not student_ids:
continue
i += 1
student_id = student_ids[0]
data_update = {
'point': 6,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
updatetable_t(url_update, data_update)
#四、课堂主动回答问题
data_update = {
'point': 6,
'class_name': '软件工程',
'sid': 102201203,
'style': 1
}
updatetable_t(url_update, data_update)
data_update = {
'point': 2,
'class_name': '软件工程',
'sid': 102201216,
'style': 1
}
updatetable_t(url_update, data_update)
#五、教师查看2(#`O)学生的排名
url_show = 'http://127.0.0.1:8000/show/information/'
data_show = {
'order': 1,
'class_name': '软件工程',
'sid': 102201539,
}
show_information_t(url_show,data_show)
data = {
'order': 1,
'class_name': '软件工程',
'sid': 102201529,
}
show_information_t(url_show,data)
if __name__ == '__main__':
#cProfile.run('main()','test_total0.txt')
main()