🎨使用 Black 格式化并做了一些微小调整

This commit is contained in:
zhxy-CN 2022-11-12 22:48:53 +08:00
parent 3855098056
commit 25cfac9c87
Signed by: zhxycn
GPG Key ID: CC305996B88B3C03

67
main.py
View File

@ -28,7 +28,7 @@ headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37",
"Accept-Encoding": "gzip, deflate, br", "Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9", "Accept-Language": "zh-CN,zh;q=0.9",
"Cookie": cookie "Cookie": cookie,
} }
@ -50,23 +50,27 @@ async def main():
exam_score_full = str(req.json()["data"]["list"][0]["manfen"]) exam_score_full = str(req.json()["data"]["list"][0]["manfen"])
exam_score = str(req.json()["data"]["list"][0]["score"]) exam_score = str(req.json()["data"]["list"][0]["score"])
exam_rank_class = str(req.json()["data"]["list"][0]["classRank"]) exam_rank_class = str(req.json()["data"]["list"][0]["classRank"])
url_exam_info = f"https://hfs-be.yunxiao.com/v3/exam/{exam_id}/same-group-analysis" url_exam_info = (
f"https://hfs-be.yunxiao.com/v3/exam/{exam_id}/same-group-analysis"
)
req = await client.get(url=url_exam_info, headers=headers) req = await client.get(url=url_exam_info, headers=headers)
exam_score_avg_class = str(req.json()["data"]["classAvg"]) exam_score_avg_class = str(req.json()["data"]["classAvg"])
exam_score_avg_grade = str(req.json()["data"]["gradeAvg"]) exam_score_avg_grade = str(req.json()["data"]["gradeAvg"])
url_exam_detail = f"https://hfs-be.yunxiao.com/v3/exam/{exam_id}/papers-analysis" url_exam_detail = (
f"https://hfs-be.yunxiao.com/v3/exam/{exam_id}/papers-analysis"
)
req = await client.get(url=url_exam_detail, headers=headers) req = await client.get(url=url_exam_detail, headers=headers)
exam_papers = req.json()["data"]["papers"] exam_papers = req.json()["data"]["papers"]
length_exam_papers = len(exam_papers) length_exam_papers = len(exam_papers)
result = ( general = (
"以下是最近一次考试的信息:\n\n" + f"以下是最近一次考试的信息:\n\n{exam_name} | 刷新时间: "
exam_name + " | 刷新时间: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + "\n\n" + f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}\n\n个人总分: "
"个人总分: " + f"\033[32m{exam_score}\033[0m" + "/" + exam_score_full + " 班级平均分: " + f"\033[32m{exam_score}\033[0m/{exam_score_full} 班级平均分: {exam_score_avg_class} "
exam_score_avg_class + " 年级平均分: " + exam_score_avg_grade + " 班级排名: " + f"年级平均分: {exam_score_avg_grade} 班级排名: {exam_rank_class}\n\n各科成绩:"
exam_rank_class + "\n\n" + "各科成绩:"
) )
table = PrettyTable( table = PrettyTable(
["科目", "成绩", "班级平均分", "年级平均分", "班级最高分", "年级最高分", "班级排名", "年级排名"]) ["科目", "成绩", "班级平均分", "年级平均分", "班级最高分", "年级最高分", "班级排名", "年级排名"]
)
for i in range(length_exam_papers): for i in range(length_exam_papers):
exam_paper_id = str(exam_papers[i]["paperId"]) exam_paper_id = str(exam_papers[i]["paperId"])
exam_subject = str(exam_papers[i]["subject"]) exam_subject = str(exam_papers[i]["subject"])
@ -74,27 +78,40 @@ async def main():
exam_subject_score_full = str(exam_papers[i]["manfen"]) exam_subject_score_full = str(exam_papers[i]["manfen"])
exam_subject_score_avg_class = str(exam_papers[i]["classAvg"]) exam_subject_score_avg_class = str(exam_papers[i]["classAvg"])
exam_subject_score_avg_grade = str(exam_papers[i]["gradeAvg"]) exam_subject_score_avg_grade = str(exam_papers[i]["gradeAvg"])
url_exam_subject_rank = f"https://hfs-be.yunxiao.com/v3/exam/" \ url_exam_subject_rank = (
f"{exam_id}/papers/{exam_paper_id}/rank-info" f"https://hfs-be.yunxiao.com/v3/exam/{exam_id}"
f"/papers/{exam_paper_id}/rank-info"
)
req = await client.get(url=url_exam_subject_rank, headers=headers) req = await client.get(url=url_exam_subject_rank, headers=headers)
exam_subject_highest_class = str(req.json()["data"]["highest"]["class"]) exam_subject_highest_class = str(
exam_subject_highest_grade = str(req.json()["data"]["highest"]["grade"]) req.json()["data"]["highest"]["class"]
)
exam_subject_highest_grade = str(
req.json()["data"]["highest"]["grade"]
)
exam_subject_rank_class = str(req.json()["data"]["rank"]["class"]) exam_subject_rank_class = str(req.json()["data"]["rank"]["class"])
exam_subject_rank_grade = str(req.json()["data"]["rank"]["grade"]) exam_subject_rank_grade = str(req.json()["data"]["rank"]["grade"])
table.add_row([exam_subject, f"\033[32m{exam_subject_score}\033[0m/{exam_subject_score_full}", table.add_row(
exam_subject_score_avg_class, exam_subject_score_avg_grade, [
exam_subject_highest_class, exam_subject_highest_grade, exam_subject_rank_class, exam_subject,
exam_subject_rank_grade]) f"\033[32m{exam_subject_score}\033[0m/{exam_subject_score_full}",
exam_subject_score_avg_class,
exam_subject_score_avg_grade,
exam_subject_highest_class,
exam_subject_highest_grade,
exam_subject_rank_class,
exam_subject_rank_grade,
]
)
clear() clear()
print(result) print(general)
print(table) print(table)
except BaseException as e: except BaseException as e:
print("获取失败: Error: ", e, " Time: ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) print(
f"获取失败: Error: {e} | Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}"
)
await asyncio.sleep(float(refresh_time)) await asyncio.sleep(float(refresh_time))
if __name__ == '__main__': if __name__ == "__main__":
tasks = [main() for _ in range(1)] asyncio.run(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
loop.close()