Skip to content

Commit

Permalink
更新日历和日程 (#710)
Browse files Browse the repository at this point in the history
* 更新日历和日程
* 重命名变量
Co-authored-by: yaoqiankun <yaoqiankun@datarc.cn>
  • Loading branch information
yqkcn committed Mar 19, 2022
1 parent feab632 commit 8ad2268
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 14 deletions.
86 changes: 86 additions & 0 deletions tests/test_work_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,89 @@ def test_parse_unknown_message(self):
msg = parse_message(xml)

self.assertTrue(isinstance(msg, UnknownMessage))

def test_parse_modify_calendar(self):
xml = """
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[modify_calendar]]></Event>
<CalId><![CDATA[wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA]]></CalId>
</xml>
"""
msg = parse_message(xml)

self.assertIsInstance(msg, events.ModifyCalendarEvent)
self.assertEqual("wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", msg.calendar_id)

def test_parse_delete_calendar(self):
xml = """
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[delete_calendar]]></Event>
<CalId><![CDATA[wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA]]></CalId>
</xml>
"""
msg = parse_message(xml)

self.assertIsInstance(msg, events.DeleteCalendarEvent)
self.assertEqual("wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", msg.calendar_id)

def test_parse_add_schedule(self):
xml = """
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[add_schedule]]></Event>
<CalId><![CDATA[wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA]]></CalId>
<ScheduleId><![CDATA[17c7d2bd9f20d652840f72f59e796AAA]]></ScheduleId>
</xml>
"""
msg = parse_message(xml)

self.assertIsInstance(msg, events.AddScheduleEvent)
self.assertEqual("wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", msg.calendar_id)
self.assertEqual("17c7d2bd9f20d652840f72f59e796AAA", msg.schedule_id)

def test_parse_modify_schedule(self):
xml = """
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[modify_schedule]]></Event>
<CalId><![CDATA[wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA]]></CalId>
<ScheduleId><![CDATA[17c7d2bd9f20d652840f72f59e796AAA]]></ScheduleId>
</xml>
"""
msg = parse_message(xml)

self.assertIsInstance(msg, events.ModifyScheduleEvent)
self.assertEqual("wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", msg.calendar_id)
self.assertEqual("17c7d2bd9f20d652840f72f59e796AAA", msg.schedule_id)

def test_parse_delete_schedule(self):
xml = """
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[delete_schedule]]></Event>
<CalId><![CDATA[wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA]]></CalId>
<ScheduleId><![CDATA[17c7d2bd9f20d652840f72f59e796AAA]]></ScheduleId>
</xml>
"""
msg = parse_message(xml)

self.assertIsInstance(msg, events.DeleteScheduleEvent)
self.assertEqual("wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", msg.calendar_id)
self.assertEqual("17c7d2bd9f20d652840f72f59e796AAA", msg.schedule_id)
18 changes: 13 additions & 5 deletions wechatpy/work/client/api/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

class WeChatCalendar(BaseWeChatAPI):
"""
https://work.weixin.qq.com/api/doc/90000/90135/92616
https://developer.work.weixin.qq.com/document/path/93624
"""

def add(self, organizer, summary, color, description="", shares=()):
"""
创建日历
https://work.weixin.qq.com/api/doc/90000/90135/92618
详情请参考
https://developer.work.weixin.qq.com/document/path/93647
:param organizer: 指定的组织者userid。注意该字段指定后不可更新
:param summary: 日历标题。1 ~ 128 字符
Expand All @@ -40,7 +42,9 @@ def add(self, organizer, summary, color, description="", shares=()):
def update(self, calendar_id, summary, color, description="", shares=()):
"""
更新日历
https://work.weixin.qq.com/api/doc/90000/90135/92619
详情请参考
https://developer.work.weixin.qq.com/document/path/93647
:param calendar_id: 日历ID
:param summary: 日历标题。1 ~ 128 字符
Expand All @@ -63,7 +67,9 @@ def update(self, calendar_id, summary, color, description="", shares=()):
def get(self, calendar_ids):
"""
获取日历
https://work.weixin.qq.com/api/doc/90000/90135/92621
详情请参考
https://developer.work.weixin.qq.com/document/path/93647
:param calendar_ids: 日历ID列表。一次最多可获取1000条
:type calendar_ids: list[str]
Expand All @@ -80,7 +86,9 @@ def get(self, calendar_ids):
def delete(self, calendar_id):
"""
删除日历
https://work.weixin.qq.com/api/doc/90000/90135/92620
详情请参考
https://developer.work.weixin.qq.com/document/path/93647
:param calendar_id: 日历ID
"""
Expand Down
39 changes: 30 additions & 9 deletions wechatpy/work/client/api/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@


class WeChatSchedule(BaseWeChatAPI):
"""
https://work.weixin.qq.com/api/doc/90000/90135/92617
"""

def add(
self,
organizer,
Expand All @@ -28,7 +24,9 @@ def add(
):
"""
创建日程
https://work.weixin.qq.com/api/doc/90000/90135/92622
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E5%88%9B%E5%BB%BA%E6%97%A5%E7%A8%8B
:param organizer: 组织者
:param start_time: 日程开始时间,Unix时间戳
Expand Down Expand Up @@ -103,7 +101,9 @@ def update(
):
"""
更新日程
https://work.weixin.qq.com/api/doc/90000/90135/92623
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E6%9B%B4%E6%96%B0%E6%97%A5%E7%A8%8B
:param organizer: 组织者
:param schedule_id: 日程ID
Expand Down Expand Up @@ -163,7 +163,9 @@ def update(
def get(self, schedule_ids):
"""
获取日程
https://work.weixin.qq.com/api/doc/90000/90135/92624
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E8%8E%B7%E5%8F%96%E6%97%A5%E7%A8%8B%E8%AF%A6%E6%83%85
:param schedule_ids: 日程ID列表。一次最多可获取1000条
:type schedule_ids: list[str]
Expand All @@ -180,7 +182,9 @@ def get(self, schedule_ids):
def delete(self, schedule_id):
"""
取消日程(删除日程)
https://work.weixin.qq.com/api/doc/90000/90135/92625
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E5%8F%96%E6%B6%88%E6%97%A5%E7%A8%8B
:param schedule_id: 日程ID
"""
Expand All @@ -189,7 +193,9 @@ def delete(self, schedule_id):
def get_by_calendar(self, calendar_id, offset=0, limit=500):
"""
获取日历下的日程列表
https://work.weixin.qq.com/api/doc/90000/90135/92626
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E8%8E%B7%E5%8F%96%E6%97%A5%E5%8E%86%E4%B8%8B%E7%9A%84%E6%97%A5%E7%A8%8B%E5%88%97%E8%A1%A8
(注意,被取消的日程也可以拉取详情,调用者需要检查status)
:param calendar_id: 日历ID
Expand All @@ -204,3 +210,18 @@ def get_by_calendar(self, calendar_id, offset=0, limit=500):
data={"cal_id": calendar_id, "offset": offset, "limit": limit},
result_processor=op.itemgetter("schedule_list"),
)

def del_users(self, schedule_id, users):
"""
删除日程参与者
详情请参考
https://developer.work.weixin.qq.com/document/path/93648#%E5%88%A0%E9%99%A4%E6%97%A5%E7%A8%8B%E5%8F%82%E4%B8%8E%E8%80%85
:param schedule_id: 日程 ID
:param users: 日程参与者 ID 列表
:type users: list[str]
"""
attendees = [{"userid": i for i in users}]
return self._post("oa/schedule/del_attendees", data={"schedule_id": schedule_id, "attendees": attendees})
63 changes: 63 additions & 0 deletions wechatpy/work/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,66 @@ class KFMsgOrEventEvent(BaseEvent):

event = "kf_msg_or_event"
token = StringField("Token")


class ModifyCalendarEvent(BaseEvent):
"""
修改日历事件
详情请参考
https://developer.work.weixin.qq.com/document/path/93651
"""

event = "modify_calendar"
calendar_id = StringField("CalId")


class DeleteCalendarEvent(BaseEvent):
"""
删除日历事件
详情请参考
https://developer.work.weixin.qq.com/document/path/93651
"""

event = "delete_calendar"
calendar_id = StringField("CalId")


class AddScheduleEvent(BaseEvent):
"""
添加日程事件
详情请参考
https://developer.work.weixin.qq.com/document/path/93651
"""

event = "add_schedule"
calendar_id = StringField("CalId")
schedule_id = StringField("ScheduleId")


class ModifyScheduleEvent(BaseEvent):
"""
修改日程事件
详情请参考
https://developer.work.weixin.qq.com/document/path/93651
"""

event = "modify_schedule"
calendar_id = StringField("CalId")
schedule_id = StringField("ScheduleId")


class DeleteScheduleEvent(BaseEvent):
"""
删除日程事件
详情请参考
https://developer.work.weixin.qq.com/document/path/93651
"""

event = "delete_schedule"
calendar_id = StringField("CalId")
schedule_id = StringField("ScheduleId")

0 comments on commit 8ad2268

Please sign in to comment.