-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwx_focus.py
More file actions
47 lines (37 loc) · 1.25 KB
/
wx_focus.py
File metadata and controls
47 lines (37 loc) · 1.25 KB
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
import time
import subprocess
import urllib.request
import json
# 当关注的微信群触发关键字消息的时候发送桌面通知
# 仅支持MAC
# 先安装 https://github.com/MustangYM/WeChatExtension-ForMac
focus_title = ['软件', '软工']
keywords = ['签到', '打卡', '签']
BASE_URL = "http://127.0.0.1:52700/wechat-plugin/"
def get_body(url):
with urllib.request.urlopen(url) as response:
body = response.read()
return json.loads(body)
def notify(title, text):
CMD = '''
on run argv
display notification (item 2 of argv) with title (item 1 of argv)
end run
'''
subprocess.call(['osascript', '-e', CMD, title, text])
user_info = get_body(BASE_URL + "user")
focus_room = [x['userId'] for x in user_info if any(i in x['title'] for i in focus_title)]
while True:
for i in focus_room:
x = get_body(BASE_URL + 'chatlog?userId={}&count=3'.format(i))
for message in x:
m = message['copyText']
if any(i in m for i in keywords):
notify(title='签到', text=m)
time.sleep(10)
break
else:
continue
break
print(time.strftime("%H:%M:%S"), "loop 10 seconds")
time.sleep(10)