Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
1970633640 committed Sep 14, 2019
1 parent fc58257 commit 05850b2
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ venv.bak/

# mypy
.mypy_cache/

.idea
*.ics
*.txt
*.html
*.json
16 changes: 16 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -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)
58 changes: 58 additions & 0 deletions json_version.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 05850b2

Please sign in to comment.