|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
10 |
|
from __future__ import absolute_import, unicode_literals |
|
3
|
|
|
|
|
4
|
10 |
|
import operator as op |
|
5
|
|
|
|
|
6
|
10 |
|
from wechatpy.client.api.base import BaseWeChatAPI |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
10 |
|
class WeChatSchedule(BaseWeChatAPI): |
|
10
|
|
|
""" |
|
11
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92617 |
|
12
|
|
|
""" |
|
13
|
|
|
|
|
14
|
10 |
|
def add( |
|
15
|
|
|
self, |
|
16
|
|
|
organizer, |
|
17
|
|
|
start_time, |
|
18
|
|
|
end_time, |
|
19
|
|
|
attendees=(), |
|
20
|
|
|
summary="", |
|
21
|
|
|
description="", |
|
22
|
|
|
is_remind=True, |
|
23
|
|
|
remind_before_event_secs=3600, |
|
24
|
|
|
is_repeat=False, |
|
25
|
|
|
repeat_type=0, |
|
26
|
|
|
location="", |
|
27
|
|
|
calendar_id="", |
|
28
|
|
|
): |
|
29
|
|
|
""" |
|
30
|
|
|
创建日程 |
|
31
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92622 |
|
32
|
|
|
|
|
33
|
|
|
:param organizer: 组织者 |
|
34
|
|
|
:param start_time: 日程开始时间,Unix时间戳 |
|
35
|
|
|
:param end_time: 日程结束时间,Unix时间戳 |
|
36
|
|
|
:param attendees: 日程参与者列表。最多支持2000人 |
|
37
|
|
|
:param summary: 日程标题。0 ~ 128 字符。不填会默认显示为“新建事件” |
|
38
|
|
|
:param description: 日程描述。0 ~ 512 字符 |
|
39
|
|
|
:param is_remind: 是否需要提醒 |
|
40
|
|
|
:param remind_before_event_secs: 日程开始(start_time)前多少秒提醒,当is_remind为1时有效 |
|
41
|
|
|
:param is_repeat: 是否重复日程 |
|
42
|
|
|
:param repeat_type: 重复类型,当is_repeat为1时有效。目前支持如下类型: |
|
43
|
|
|
0 - 每日 |
|
44
|
|
|
1 - 每周 |
|
45
|
|
|
2 - 每月 |
|
46
|
|
|
5 - 每年 |
|
47
|
|
|
7 - 工作日 |
|
48
|
|
|
:param location: 日程地址。0 ~ 128 字符 |
|
49
|
|
|
:param calendar_id: 日程所属日历ID。注意,这个日历必须是属于组织者(organizer)的日历;如果不填,那么插入到组织者的默认日历上 |
|
50
|
|
|
|
|
51
|
|
|
:type organizer: str |
|
52
|
|
|
:type start_time: int |
|
53
|
|
|
:type end_time: int |
|
54
|
|
|
:type attendees: list[str] |
|
55
|
|
|
:type summary: str |
|
56
|
|
|
:type description: str |
|
57
|
|
|
:type is_remind: bool |
|
58
|
|
|
:type remind_before_event_secs: int |
|
59
|
|
|
:type is_repeat: bool |
|
60
|
|
|
:type repeat_type: int |
|
61
|
|
|
:type location: str |
|
62
|
|
|
:type calendar_id: str |
|
63
|
|
|
|
|
64
|
|
|
:return: 日程ID |
|
65
|
|
|
:rtype: str |
|
66
|
|
|
""" |
|
67
|
|
|
|
|
68
|
|
|
data = { |
|
69
|
|
|
'schedule': { |
|
70
|
|
|
'organizer': organizer, |
|
71
|
|
|
'start_time': start_time, |
|
72
|
|
|
'end_time': end_time, |
|
73
|
|
|
'attendees': [{'userid': userid} for userid in attendees], |
|
74
|
|
|
'summary': summary, |
|
75
|
|
|
'description': description, |
|
76
|
|
|
'reminders': { |
|
77
|
|
|
'is_remind': int(is_remind), |
|
78
|
|
|
'remind_before_event_secs': remind_before_event_secs, |
|
79
|
|
|
'is_repeat': int(is_repeat), |
|
80
|
|
|
'repeat_type': repeat_type, |
|
81
|
|
|
}, |
|
82
|
|
|
'location': location, |
|
83
|
|
|
'cal_id': calendar_id, |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
return self._post('oa/schedule/add', data=data, result_processor=op.itemgetter('schedule_id')) |
|
87
|
|
|
|
|
88
|
10 |
|
def update( |
|
89
|
|
|
self, |
|
90
|
|
|
organizer, |
|
91
|
|
|
schedule_id, |
|
92
|
|
|
start_time, |
|
93
|
|
|
end_time, |
|
94
|
|
|
attendees=(), |
|
95
|
|
|
summary="", |
|
96
|
|
|
description="", |
|
97
|
|
|
is_remind=True, |
|
98
|
|
|
remind_before_event_secs=3600, |
|
99
|
|
|
is_repeat=False, |
|
100
|
|
|
repeat_type=0, |
|
101
|
|
|
location="", |
|
102
|
|
|
calendar_id="", |
|
103
|
|
|
): |
|
104
|
|
|
""" |
|
105
|
|
|
更新日程 |
|
106
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92623 |
|
107
|
|
|
|
|
108
|
|
|
:param organizer: 组织者 |
|
109
|
|
|
:param schedule_id: 日程ID |
|
110
|
|
|
:param start_time: 日程开始时间,Unix时间戳 |
|
111
|
|
|
:param end_time: 日程结束时间,Unix时间戳 |
|
112
|
|
|
:param attendees: 日程参与者列表。最多支持2000人 |
|
113
|
|
|
:param summary: 日程标题。0 ~ 128 字符。不填会默认显示为“新建事件” |
|
114
|
|
|
:param description: 日程描述。0 ~ 512 字符 |
|
115
|
|
|
:param is_remind: 是否需要提醒 |
|
116
|
|
|
:param remind_before_event_secs: 日程开始(start_time)前多少秒提醒,当is_remind为1时有效 |
|
117
|
|
|
:param is_repeat: 是否重复日程 |
|
118
|
|
|
:param repeat_type: 重复类型,当is_repeat为1时有效。目前支持如下类型: |
|
119
|
|
|
0 - 每日 |
|
120
|
|
|
1 - 每周 |
|
121
|
|
|
2 - 每月 |
|
122
|
|
|
5 - 每年 |
|
123
|
|
|
7 - 工作日 |
|
124
|
|
|
:param location: 日程地址。0 ~ 128 字符 |
|
125
|
|
|
:param calendar_id: 日程所属日历ID。注意,这个日历必须是属于组织者(organizer)的日历;如果不填,那么插入到组织者的默认日历上 |
|
126
|
|
|
|
|
127
|
|
|
:type organizer: str |
|
128
|
|
|
:type schedule_id: str |
|
129
|
|
|
:type start_time: int |
|
130
|
|
|
:type end_time: int |
|
131
|
|
|
:type attendees: list[str] |
|
132
|
|
|
:type summary: str |
|
133
|
|
|
:type description: str |
|
134
|
|
|
:type is_remind: bool |
|
135
|
|
|
:type remind_before_event_secs: int |
|
136
|
|
|
:type is_repeat: bool |
|
137
|
|
|
:type repeat_type: int |
|
138
|
|
|
:type location: str |
|
139
|
|
|
:type calendar_id: str |
|
140
|
|
|
""" |
|
141
|
|
|
|
|
142
|
|
|
data = { |
|
143
|
|
|
'schedule': { |
|
144
|
|
|
'organizer': organizer, |
|
145
|
|
|
'schedule_id': schedule_id, |
|
146
|
|
|
'start_time': start_time, |
|
147
|
|
|
'end_time': end_time, |
|
148
|
|
|
'attendees': [{'userid': userid} for userid in attendees], |
|
149
|
|
|
'summary': summary, |
|
150
|
|
|
'description': description, |
|
151
|
|
|
'reminders': { |
|
152
|
|
|
'is_remind': int(is_remind), |
|
153
|
|
|
'remind_before_event_secs': remind_before_event_secs, |
|
154
|
|
|
'is_repeat': int(is_repeat), |
|
155
|
|
|
'repeat_type': repeat_type, |
|
156
|
|
|
}, |
|
157
|
|
|
'location': location, |
|
158
|
|
|
'cal_id': calendar_id, |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
return self._post('oa/schedule/update', data=data) |
|
162
|
|
|
|
|
163
|
10 |
|
def get(self, schedule_ids): |
|
164
|
|
|
""" |
|
165
|
|
|
获取日程 |
|
166
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92624 |
|
167
|
|
|
|
|
168
|
|
|
:param schedule_ids: 日程ID列表。一次最多可获取1000条 |
|
169
|
|
|
:type schedule_ids: list[str] |
|
170
|
|
|
|
|
171
|
|
|
:return: 日程列表 |
|
172
|
|
|
:rtype: list[dict] |
|
173
|
|
|
""" |
|
174
|
|
|
return self._post( |
|
175
|
|
|
'oa/schedule/get', data={'schedule_id_list': schedule_ids}, result_processor=op.itemgetter('schedule_list') |
|
176
|
|
|
) |
|
177
|
|
|
|
|
178
|
10 |
|
def delete(self, schedule_id): |
|
179
|
|
|
""" |
|
180
|
|
|
取消日程(删除日程) |
|
181
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92625 |
|
182
|
|
|
|
|
183
|
|
|
:param schedule_id: 日程ID |
|
184
|
|
|
""" |
|
185
|
|
|
return self._post('oa/schedule/del', data={'schedule_id': schedule_id}) |
|
186
|
|
|
|
|
187
|
10 |
|
def get_by_calendar(self, calendar_id, offset=0, limit=500): |
|
188
|
|
|
""" |
|
189
|
|
|
获取日历下的日程列表 |
|
190
|
|
|
https://work.weixin.qq.com/api/doc/90000/90135/92626 |
|
191
|
|
|
(注意,被取消的日程也可以拉取详情,调用者需要检查status) |
|
192
|
|
|
|
|
193
|
|
|
:param calendar_id: 日历ID |
|
194
|
|
|
:param offset: 分页,偏移量, 默认为0 |
|
195
|
|
|
:param limit: 分页,预期请求的数据量,默认为500,取值范围 1 ~ 1000 |
|
196
|
|
|
|
|
197
|
|
|
:return: 日程列表 |
|
198
|
|
|
:rtype: list[dict] |
|
199
|
|
|
""" |
|
200
|
|
|
return self._post( |
|
201
|
|
|
'oa/schedule/get_by_calendar', |
|
202
|
|
|
data={'cal_id': calendar_id, 'offset': offset, 'limit': limit}, |
|
203
|
|
|
result_processor=op.itemgetter('schedule_list'), |
|
204
|
|
|
) |
|
205
|
|
|
|