diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 894a44c..a755970 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,9 @@ venv.bak/ # mypy .mypy_cache/ + +.idea +*.ics +*.txt +*.html +*.json \ No newline at end of file diff --git a/1.py b/1.py new file mode 100644 index 0000000..c316373 --- /dev/null +++ b/1.py @@ -0,0 +1,16 @@ +from bs4 import BeautifulSoup + +x = str(open("1.html", 'r', encoding='UTF-8').readlines()) +s = BeautifulSoup(x, features="html.parser") +for c in s.find_all(class_="cell"): + # print(c) + # print(c.find(class_="title").string, c.find(class_="teacher").contents, c.find(class_="classroom").string) + title = c.find(class_="title").string + teachers = [] + for temp in c.find(class_="teacher").contents: + teachers.append(temp.string) + teacher = "、".join(teachers) + classroom=c.find(class_="classroom").string + timespan=c.find(class_="timespan").string + weekspan=c.find(class_="week").string + print(title, teacher, classroom,timespan,weekspan) \ No newline at end of file diff --git a/json_version.py b/json_version.py new file mode 100644 index 0000000..2036a22 --- /dev/null +++ b/json_version.py @@ -0,0 +1,58 @@ +import json, demjson +from icalendar import Calendar, Event +from datetime import datetime,timedelta +from pytz import UTC # timezone +from pytz import timezone + +cal = Calendar() +cal.add('prodid', '-//ustc timetable//timetable//CN') +cal.add('version', '2.0') +cal.add('TZID','Asia/Shanghai') +cal.add('X-WR-TIMEZONE','Asia/Shanghai') + +MODE = "CN" +FIRST = datetime.strptime("2019-09-01 00:00:00","%Y-%m-%d %H:%M:%S").astimezone(timezone("Asia/Shanghai")) # 学期第一周的周日,即开学前一天 + +s = str(open("1.json", 'r', encoding='UTF-8').readlines()) +xx = demjson.decode(s) +x = (demjson.decode(xx[0])) +print(x['studentTableVm']['name'], x['studentTableVm']['code'], x['studentTableVm']['department'], "本学期学分", + x['studentTableVm']['credits'], x['studentTableVm']['major']) +ii = 0 +for c in x['studentTableVm']['activities']: + summary = c['courseName'] + location = " ".join([c['campus'], c['room']]) + description = " ".join([c['campus'], c['building'], " ".join(c['teachers']), c['weeksStr'] + "周", c['lessonCode'], + str(c['credits']) + '学分']) + status = 0 # 0每周 1单周 2双周 + weeksStr = str(c['weeksStr']) + if weeksStr.find("单") > -1: + status = 1 + weeksStr=weeksStr.replace('单', '') + elif weeksStr.find("双") > -1: + status = 2 + weeksStr=weeksStr.replace('双', '') + startWeek = int(weeksStr.split('-')[0]) + endWeek = int(weeksStr.split('-')[1]) + weekday = int(c['weekday']) + sHour=int(c['startDate'].split(':')[0]) + sMin = int(c['startDate'].split(':')[1]) + eHour=int(c['endDate'].split(':')[0]) + eMin = int(c['endDate'].split(':')[1]) + weeks=[] + if status==0: + weeks.extend(range(startWeek-1,endWeek)) + else: + weeks.extend(range(startWeek-1, endWeek ,2)) + for i in weeks: + event = Event() + event.add('summary', summary) + event.add('location', location) + event.add('description', description) + event.add('dtstart',FIRST+timedelta(days=weekday,weeks=i,hours=sHour,minutes=sMin)) + event.add('dtend', FIRST+timedelta(days=weekday,weeks=i,hours=eHour,minutes=eMin)) + event.add('dtstamp', FIRST+timedelta(days=weekday,weeks=i,hours=sHour,minutes=sMin)) + cal.add_component(event) +f = open('example.ics', 'wb') +f.write(cal.to_ical()) +f.close()