#!/usr/bin/env python
# -*- coding: utf-8 -*-
from threading import Timer
from itchat.content import *
import requests
import itchat
#獲取金山詞霸每日一句英語
def getNews():
#打開金山詞霸開放平臺API
url = "http://open.iciba.com/dsapi"
req = requests.get(url)
#"content":"Interests are anchors, and I believe they will bring peace and even happiness in the end."
contents = req.json()['content']
trans = req.json()['translation']
return contents,trans
#發送消息
def sendNews():
#global my_love
try:
#會彈出網頁二維碼掃描登錄微信
itchat.auto_login()
#不想每次都掃描,登錄時預配置
#itchat.auto_login(hotReload=True)
#itchat.run()
#1.想給誰發信息,先找到該朋友,備注名
my_friend = itchat.search_friends(name = r'lu')
#2.找到UserName
my_love = my_friend[0]["UserName"]
#new_cont, new_trans = getNews()
#print(new_cont)
#print(new_trans)
msg1 = str(getNews()[0]) #獲取金山詞霸字典內容
msg2 = str(getNews()[1][5:])
msg = '翻譯:'
cont = str(msg+msg2)
#3.發送消息
#調試,直接給微信手機助手發送消息
itchat.send(msg1,toUserName = "filehelper")
itchat.send(cont,toUserName = 'filehelper')
#給微信好友發送消息
itchat.send(msg1,toUserName = my_love)
itchat.send(cont,toUserName = my_love)
#每隔86400秒發送一次,每天發送一次
Timer(80000,sendNews).start()
except:
msg4 = "最愛你的人來啦!!!"
itchat.send(msg4,toUserName = my_love)
#itchat.logout()
#調試函數
def test():
itchat.auto_login()
itchat.send(u'測試消息發送','filehelper')#發送給文件助手
if __name__ == '__main__':
sendNews()
python3使用itchat發送微信
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- weChatThread線程類 之前一直不會python多線程,寫這個程序的時候,發現不用多線程會陷入無限未響應狀...