-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
108 lines (88 loc) · 3.25 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import datetime
from icalendar import Calendar, Event, Alarm
import uuid
from datetime import timezone, timedelta
print("Please choose your language:")
print("请选择你的语言:")
print("1. English")
print("2. 中文")
print("请输入你的选择:")
# language = input("Please input your language:")
language = "2"
print("Please enter your medication cycle:")
print("请输入你的药物周期:")
# cycle_taking_pill = input()
cycle_taking_pill = 21
print("Please enter your withdrawal period:")
print("请输入你的停药周期:")
# cycle_stop_pill = input()
cycle_stop_pill = 7
reminderSetCN = {
"calname": "短效小助手",
"eventNameTakePill": "宝儿今天要吃药哦",
"eventNameHaveARest": "宝儿今天得休息哦",
"takingPillReminder": "该吃药了喔",
}
reminderSetEN = {
"calname": "Short-term assistant",
"eventNameTakePill": "Baby you need to take a pill today",
"eventNameHaveARest": "Baby today is resting",
"takingPillReminder": "Baby, It's time to take a pill",
}
reminderSet = reminderSetEN
if language == "2":
reminderSet = reminderSetCN
def cread_event(eventName, start, end, createAlarm=False):
# 创建事件/日程
event = Event()
event.add('summary', eventName)
# datetime.datetime.now()
dt_now = datetime.datetime.now(tz=tz_utc_8)
event.add('dtstart', start)
event.add('dtend', end)
# 创建时间
event.add('dtstamp', dt_now)
# 重复
event.add('rrule', {'freq': 'daily', 'interval': 28})
# 提醒
if createAlarm:
alarm1 = Alarm()
alarm1.add("action", "DISPLAY")
alarm1.add("description", reminderSet["takingPillReminder"])
alarm1.add("trigger", timedelta(minutes=0))
event.add_component(alarm1)
alarm2 = Alarm()
alarm2.add("action", "DISPLAY")
alarm2.add("description", reminderSet["takingPillReminder"])
alarm2.add("trigger", timedelta(minutes=60))
event.add_component(alarm2)
# UID保证唯一
event['uid'] = str(uuid.uuid1())
return event
cal = Calendar()
cal.add('prodid', '-//Apple Inc.//Mac OS X 10.12//EN')
cal.add('version', '2.0')
cal.add('x-wr-calname', reminderSet["calname"])
cal.add('method', 'PUBLISH')
cal.add('x-apple-calendar-color', '#FC4208')
cal.add('class', 'PRIVATE')
tz_utc_8 = timezone(timedelta(hours=8))
startTime = datetime.datetime(2022, 4, 21, 18, 0, 0, 0, tzinfo=tz_utc_8)
# print(startTime)
for i in range(cycle_taking_pill):
endTime = startTime + timedelta(minutes=1)
eventName = reminderSet["eventNameTakePill"] + \
"(" + str(i+1) + "/" + str(cycle_taking_pill) + ")"
event = cread_event(eventName, startTime, endTime, 1)
cal.add_component(event)
startTime = endTime + timedelta(minutes=-1, days=1)
for i in range(cycle_stop_pill):
endTime = startTime + timedelta(minutes=1)
eventName = reminderSet["eventNameHaveARest"] + \
"(" + str(i+1) + "/" + str(cycle_stop_pill) + ")"
event = cread_event(eventName, startTime, endTime)
cal.add_component(event)
startTime = endTime + timedelta(minutes=-1, days=1)
# print(cal.to_ical())
with open("test.ics", "wb") as f:
f.write(cal.to_ical())