-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwechat.py
More file actions
54 lines (46 loc) · 1.61 KB
/
Copy pathwechat.py
File metadata and controls
54 lines (46 loc) · 1.61 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
48
49
50
51
52
53
54
"""
Send wechat message to participants in psychological experiments.
Created by Yuki Tang / yukitang0703@gmail.com / Feb 2019
"""
__author__ = "Yuki Tang"
__version__ = "1.0"
__email__ = "yukitang0703@gmail.com"
__status__ = "alpha"
import itchat
import time
class wechat:
def __init__():
def wechat_login(Status = True):
"""scan the qrcode to login in on web server
Status -- True: stay signed in; False: scan qrcode to sign in each time
"""
itchat.auto_login(True)
itchat.send('登录成功!登录状态为%s'%Status,toUserName = 'filehelper')
return True
def get_user():
user = itchat.get_friends(update = True)
#print(type(user))
def search_user(who):
friend = itchat.search_friends(name=who)
itchat.send('找到用户'+who,toUserName = 'filehelper')
return friend
def send_msg(msg, who,lapse = 0):
"""
"""
time.sleep(lapse)
friend = wechat.search_user(who)
if friend!=None:
username = friend[0]['UserName']
itchat.send_msg(msg,username)
itchat.send('已发送给用户'+who+':'+msg,toUserName = 'filehelper')
return True
else:
itchat.send('没有找到用户'+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),toUserName = 'filehelper')
return None
def wechat_logout():
itchat.send('登出',toUserName = 'filehelper')
itchat.logout()
print("成功登出!")
wechat.wechat_login()
#wechatSend.get_user()
wechat.send_msg('早上好呀','许相宜')