Created
September 10, 2021 06:12
-
-
Save ouyen/14d9d6433ddebb405c265750d41ee601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 要添加一个新单元,输入 '# %%' | |
# 要添加一个新的标记单元,输入 '# %% [markdown]' | |
# %% | |
with open('1.txt','r') as f: | |
x=f.read() | |
# x | |
# %% | |
start=x.find('课程名 \t课程类别 \t学分 \t周学时 \t教师 \t班号 \t开课单位 \t教室信息 \t选课结果 \tIP地址 \t操作时间\n') | |
# %% | |
end=x.find('Page 1 of 1 First') | |
# %% | |
# len(('课程名 \t课程类别 \t学分 \t周学时 \t教师 \t班号 \t开课单位 \t教室信息 \t选课结果 \tIP地址 \t操作时间\n')) | |
# %% | |
useful_text=x[start+57:end] | |
# %% | |
# temp_message_list=useful_text.split('\t已选上') | |
# class_list=[] | |
# for i in range(len(temp_message_list)-1): | |
# if i==0: | |
# temp=temp_message_list[i].split('\t') | |
# else: | |
# temp=temp_message_list[i][temp_message_list[i].find('\n')+1:].split('\t') | |
# message=temp[7].split('\n') | |
# nead_clean=message[-2].find('(备注') | |
# if nead_clean!=-1: | |
# message[-2]=message[-2][:nead_clean] | |
# if message[-1]=='考试方式:堂考、论文、或统一时间考试 ': | |
# message[-1]=None | |
# else: | |
# message[-1]=message[-1][message[-1].find('考试时间:')+5:message[-1].find(';')] | |
# class_list.append({'class_name':temp[0],'teacher':temp[4],'class_time':message[:-1],'exam':message[-1]}) | |
# %% | |
useful_text | |
# %% | |
useful_text.split('\t')[0::10] | |
# %% | |
useful_text_list=useful_text.split('\t') | |
class_list_new=[] | |
for i in range(int(len(useful_text.split('\t'))/10)): | |
if i==0: | |
class_name=useful_text_list[10*i] | |
else: | |
class_name=useful_text_list[10*i].split('\n')[-1] | |
message=useful_text_list[10*i+7].split('\n') | |
nead_clean=message[-2].find('(备注') | |
if nead_clean!=-1: | |
message[-2]=message[-2][:nead_clean] | |
if message[-1]=='考试方式:堂考、论文、或统一时间考试 ': | |
message[-1]=None | |
else: | |
message[-1]=message[-1][message[-1].find('考试时间:')+5:message[-1].find(';')] | |
class_list_new.append({'name':class_name,'time':message[:-1],'exam':message[-1],'result':useful_text_list[10*i+8]}) | |
# %% | |
f=open('result.ics','w') | |
f.write('BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//superman-industries.com//ical-generator//EN\nNAME:课表\nX-WR-CALNAME:课表\nX-WR-TIMEZONE:Asia/Shanghai\n') | |
f.close() | |
# %% | |
hash('概率统计 (B)') | |
# %% | |
class_list_new[0] | |
# %% | |
term_start='20210913T000000Z' | |
term_end='20220103T000000Z' | |
week_dict={ '一' : 1, '二' : 2, '三' : 3, '四' : 4, '五' : 5, '六' : 6, '七' : 7} | |
class_time_dict={1:['0000','0050'],2:['0100','0150'],3:['0210','0300'],4:['0310','0400'],5:['0500','0550'],6:['0600','0650'],7:['0710','0800'],8:['0810','0900'],9:['0910','1000'],10:['1040','1130'],11:['1140','1230'],12:['1240','1330']} | |
is_ord={'单':0,'双':1,'每':0} | |
INTERVAL={'单':2,'双':2,'每':1} | |
# %% | |
def add_class(which_class,which_time,file): | |
# with open('3.txt','a') as f: | |
f=open(file,'a') | |
f.writelines('BEGIN:VEVENT\n') | |
uid=abs(hash(class_list_new[which_class]['name']+str(which_time))) | |
class_time=class_list_new[which_class]['time'][which_time].split(' ')[1] | |
f.writelines('UID:'+str(uid)+'@test.cn\n') | |
f.writelines('SEQUENCE:0\n') | |
day=int(term_start[6:8])+week_dict[class_time[3]]+is_ord[class_time[0]]*7-1 | |
start_date=term_start[:6]+'0'*(2-len(str(day)))+str(day) | |
x1=class_time.find('~') | |
x2=class_time.find('节') | |
DTSTART=start_date+'T'+class_time_dict[int(class_time[4:x1])][0]+'00Z' | |
DTEND=start_date+'T'+class_time_dict[int(class_time[x1+1:x2])][1]+'00Z' | |
f.writelines('DTSTART:'+DTSTART+'\n') | |
f.writelines('DTEND:'+DTEND+'\n') | |
f.writelines('RRULE:FREQ=WEEKLY;INTERVAL='+str(INTERVAL[class_time[0]])+';UNTIL='+term_end+'\n') | |
f.writelines('SUMMARY:'+class_list_new[which_class]['name']+'\n') | |
f.writelines('LOCATION:'+class_list_new[which_class]['time'][which_time].split(' ')[-1]+'\n') | |
f.writelines('BEGIN:VALARM\nACTION:DISPLAY\nTRIGGER:-PT30M\nDESCRIPTION:'+class_list_new[which_class]['name']+class_list_new[which_class]['time'][which_time].split(' ')[-1]+'\n') | |
f.writelines('END:VALARM\nEND:VEVENT\n') | |
f.close() | |
# %% | |
class_list_new | |
# %% | |
exam_dict={'上午':['0030','0230'],'下午':['0600','0800'],'晚上':['1030','1230']} | |
def add_exam(class_num,file): | |
f=open(file,'a') | |
f.writelines('BEGIN:VEVENT\n') | |
uid=abs(hash(class_list_new[i]['name']+class_list_new[i]['exam'])) | |
f.writelines('UID:'+str(uid)+'@test.cn\nSEQUENCE:0\n') | |
f.writelines('DTSTART:'+class_list_new[i]['exam'][:8]+'T'+exam_dict[class_list_new[i]['exam'][8:]][0]+'00Z\n') | |
f.writelines('DTEND:'+class_list_new[i]['exam'][:8]+'T'+exam_dict[class_list_new[i]['exam'][8:]][1]+'00Z\n') | |
f.writelines('SUMMARY:'+class_list_new[i]['name']+'期末'+'\n') | |
f.writelines('BEGIN:VALARM\nACTION:DISPLAY\nTRIGGER:-PT30M\nDESCRIPTION:'+class_list_new[i]['name']+'期末'+'\n') | |
f.writelines('END:VALARM\nEND:VEVENT\n') | |
# %% | |
for i in range(len(class_list_new)): | |
if ((class_list_new[i]['result']=='已选上 ')): | |
for j in range(len(class_list_new[i]['time'])): | |
add_class(i,j,'result.ics') | |
if class_list_new[i]['exam']: | |
add_exam(i,'result.ics') | |
# %% | |
with open('result.ics','a') as f: | |
f.writelines('END:VCALENDAR') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment