forked from SunsetYe66/ClasstableToIcal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cqu_config.py
59 lines (55 loc) · 2.17 KB
/
cqu_config.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
from calendar import weekday
from os import times
def classTimeTranslate(timeStr: str):
classList = list()
weekDayRef = dict()
weekDayRef["一"] = 1
weekDayRef["二"] = 2
weekDayRef["三"] = 3
weekDayRef["四"] = 4
weekDayRef["五"] = 5
weekDayRef["六"] = 6
weekDayRef["日"] = 7
# 周次处理(多个区间拆分为多个)
while True:
if timeStr.find(',') != -1: # 如果周次有多个范围
(weekRange, timeStr) = timeStr.split(',', 1)
if weekRange.find('-') != -1: # 如果周次是区间
(startWeek, endWeek) = weekRange.split('-')
else:
startWeek = endWeek = weekRange
classList.append(dict())
classList[-1].setdefault("StartWeek", int(startWeek))
classList[-1].setdefault("EndWeek", int(endWeek))
classList[-1].setdefault("WholeWeek", False)
else:
(weekRange, timeStr) = timeStr.split('周', 1)
if weekRange.find('-') != -1: # 如果周次是区间
(startWeek, endWeek) = weekRange.split('-')
else:
startWeek = endWeek = weekRange
classList.append(dict())
classList[-1].setdefault("StartWeek", int(startWeek))
classList[-1].setdefault("EndWeek", int(endWeek))
classList[-1].setdefault("WholeWeek", False)
break # 结束周次处理
# 处理“占周不占时间”
if timeStr.find('节') == -1:
for i in range(len(classList)):
classList[i]["WholeWeek"] = True
return classList
# 星期几
weekDay = timeStr[2]
timeStr = timeStr[3:]
for i in range(len(classList)):
classList[i].setdefault("Weekday", weekDayRef[weekDay])
# 节次
classTime = timeStr[:-1]
if classTime.find('-') != -1: # 如果节次是区间
(classStartTime, classEndTime) = classTime.split('-')
else:
classStartTime = classEndTime = classTime
for i in range(len(classList)):
classList[i].setdefault("ClassStartTimeId", int(classStartTime))
classList[i].setdefault("ClassEndTimeId", int(classEndTime))
return classList