/
classroom.py
64 lines (46 loc) · 1.92 KB
/
classroom.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
55
56
57
58
59
60
61
62
63
64
import session
# 教室使用情况API的基础URL
baseUrl = "http://tm.bnuz.edu.cn/api/"
# 教学楼API URL
buildingsUrl = baseUrl + "place/buildings"
# 教室API URL
placesUrl = buildingsUrl + "/:building/places"
# 教室使用情况API URL
usagesUrl = placesUrl + "/:place/usages"
# 获取教学楼
def getBuildings():
response = session.get(buildingsUrl)
return response.json()
# 获取教室
def getPlaces(building):
url = placesUrl.replace(":building", building)
response = session.get(url)
return response.json()
# 获取教室使用情况
def getUsages(building, place):
url = usagesUrl.replace(":building", building).replace(":place", place)
response = session.get(url)
return response.json()
# 打印考试周的考试科目
def printTestClass():
print("开始获取考试科目信息...\n")
buildings = getBuildings()
for building in buildings['buildings']:
places = getPlaces(building)
for place in places:
usages = getUsages(building, place["id"])
for usage in usages:
startWeek = usage["startWeek"]
_type = usage["type"]
if _type == "ks" and startWeek == 18 or startWeek == 19:
placeName = place["name"]
department = usage["department"]
subject = usage["description"]
dayOfWeek = usage["dayOfWeek"]
startSection = usage["startSection"]
totalSection = usage["totalSection"]
endSection = startSection + totalSection - 1
print("{} {} {} 第{}周 星期{} 第{} - {}节".format(department, subject, placeName,
startWeek, dayOfWeek,
startSection, endSection))
print("\n考试科目获取完毕,祝您愉快 >_+<")