因爲各類緣由,很久沒更新了,之後要堅持更新。。。 今天我就教你們如何作一個風趣又不失逼格的程序員。利用 python 天天給你最心愛的人,發送微信消息,說聲晚安。 這篇文章參考與【癡海】公衆號的文章,有興趣的關注一塊兒學習Python 代碼很容易看懂,因此再也不囉嗦直接上代碼了。注意的是itchat庫github上也有基本的用法python
pip install itchatgit
#!/usr/bin/python3
# -*-coding:utf-8 -*-
#Author:Eminjan
#@Time :2018/5/14 21:31
import requests
import itchat
def get_news():
# 獲取金山詞霸每日一句,英文和翻譯
url = "http://open.iciba.com/dsapi"
r = requests.get(url)
contents = r.json()['content']
translation = r.json()['translation']
return contents,translation
def send_news():
try:
# 登錄你的微信帳號,會彈出登陸二維碼,掃描就可
itchat.auto_login(hotReload=True)
# 獲取你對應的好友備註
my_firend = itchat.search_friends(name="小明")
XiaoMing = my_firend[0]["UserName"]
# 獲取金山字典的內容
message1 = str(get_news()[0])
content = str(get_news()[1][17:])
message2 = str(content)
message3 = "來自最愛你的人"
# 發送消息
itchat.send(message1,toUserName=XiaoMing )
itchat.send(message2,toUserName=XiaoMing )
itchat.send(message3,toUserName=XiaoMing )
except:
message4 = u"今天最愛你的人出現了^^^^^"
itchat.send(message4, toUserName=XiaoMing )
def main():
send_news()
if __name__ == '__main__':
main()
複製代碼