Skip to content

Commit 7284073

Browse files
committed
Change method to generate uid
The uid of the same lesson is now same, so the same lesson will not be imported twice.
1 parent e63533d commit 7284073

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

calender.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@ class Event:
77
begin = ''
88
end = ''
99
description = ''
10+
identifier = '' # used to generate uid
1011

1112
def __init__(self) -> None:
1213
pass
1314

1415
def get_str(self) -> None:
1516
begin_str = self.begin.strip() \
16-
.replace(' ', 'T').replace('-', '').replace(':', '')
17+
.replace(' ', 'T').replace('-', '').replace(':', '') + '00'
1718
end_str = self.end.strip() \
18-
.replace(' ', 'T').replace('-', '').replace(':', '')
19+
.replace(' ', 'T').replace('-', '').replace(':', '') + '00'
1920
disc_str = self.description.strip() \
2021
.replace('\n', '\\n')
2122
name_str = self.name.strip() \
2223
.replace('\n', '\\n')
23-
uid_str = str(uuid.uuid4())
24+
25+
namespace = uuid.UUID('7e6ec0dd-0d77-41d1-82b4-4469894007dd')
26+
uid_str = str(uuid.uuid3(namespace, self.identifier))
2427
uid_str = uid_str + '@' + uid_str[:4] + '.org'
2528

2629
s = ''
2730
s += 'BEGIN:VEVENT\n'
28-
s += 'DTSTART;TZID=Asia/Shanghai:' + begin_str + '00\n'
29-
s += 'DTEND;TZID=Asia/Shanghai:' + end_str + '00\n'
31+
s += 'DTSTART;TZID=Asia/Shanghai:' + begin_str + '\n'
32+
s += 'DTEND;TZID=Asia/Shanghai:' + end_str + '\n'
3033
s += 'UID:' + uid_str + '\n'
3134
s += 'DESCRIPTION:' + disc_str + '\n'
3235
s += 'SUMMARY:' + name_str + '\n'

course.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def generate_ics(self, courses: List, first_date: str) -> None:
207207
disc += '授课老师: ' + course['teacher']
208208
e.description = disc
209209

210+
e.identifier = begin_str + ' ' + course['code']
211+
# used to generate uid
212+
210213
c.add(e)
211214

212215
with open('courses.ics', 'w', encoding='utf-8', newline='\n') as ics_file:

0 commit comments

Comments
 (0)