Skip to content

Commit 8586f79

Browse files
authored
Create weichat_send_news.md
1 parent 3935fb0 commit 8586f79

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

weichat_send_news.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
``` python
2+
from __future__ import unicode_literals
3+
from threading import Timer
4+
from wxpy import *
5+
import requests
6+
import itchat
7+
def get_news():
8+
url = "http://open.iciba.com/dsapi";
9+
r = requests.get(url);
10+
contents = r.json()['content'];
11+
translation = r.json()['translation'];
12+
return contents,translation;
13+
def send_news():
14+
try:
15+
# 登录你的微信号,会弹出网页二维码,扫描即可
16+
itchat.auto_login(hotReload=True);
17+
#获取对应的好友备注
18+
#改成你最心爱的人的名字
19+
my_friend = itchat.search_friends(name=u'彩虹宝宝');
20+
#获取对应名称的一串数字
21+
rainbowBB = my_friend[0]["UserName"];
22+
#获取金三词典的内容
23+
msg1 = str(get_news()[0]);
24+
content = str(get_news()[1][17:]);
25+
msg2 = str(content);
26+
msg3 = "来自你最爱的人";
27+
#发送消息
28+
itchat.send(msg1,toUserName=rainbowBB);
29+
itchat.send(msg2,toUserName=rainbowBB);
30+
itchat.send(msg3,toUserName=rainbowBB);
31+
# 每 86400 秒(1天)发送一次
32+
t = time(86400,send_news());
33+
t.start();
34+
except:
35+
msg4 = u"今天最爱的人出现啦";
36+
itchat.send(msg4,toUserName=rainbowBB);
37+
38+
if __name__ == "__main__":
39+
send_news()
40+
```
41+
42+
##效果
43+
![效果](https://i.loli.net/2019/02/17/5c692f140fd3f.jpg)

0 commit comments

Comments
 (0)