溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python實現微信每日一句自動發送給喜歡的人

發布時間:2020-09-27 18:42:36 來源:腳本之家 閱讀:221 作者:正經男大學生BRLF 欄目:開發技術

本文實例為大家分享了python實現微信每日一句自動發送的具體代碼,供大家參考,具體內容如下

參考了一篇博客:教你使用python實現微信每天給女朋友說晚安

代碼:

# -*- coding: utf-8 -*-
'''
這是一個用來測試微信自動發送消息的demo
恩,主要就是用到了一個微信庫--wxpy
安裝很簡單 pip install wxpy
下面就開始吧
主要就兩個函數
1、getNews();用以獲取信息
2、sendNews();用以發送信息

我這里發送消息用的是for循環本意是群發,但是!但是!但是!程序發的太快會被微信禁掉,大概40個人左右就會被禁,以后可以試試sleep一下。

另外vscode中自定義python編譯器:
Ctrl+shift+p, 選擇 python: Select Interpreter
'''


from __future__ import unicode_literals
from wxpy import *
import requests
from threading import Timer

itchat = Bot(console_qr=2,cache_path="botoo.pkl")
def getNews():
 url = "http://open.iciba.com/dsapi/"
 r = requests.get(url)
 content = r.json()['content']
 note = r.json()['note']
 return content, note

def sendNews():
 try:
  #這里是備注
  friend = itchat.friends().search(name = u'xxx')

  content = getNews()
  print(content)
  message1 = str(content[0])
  message2 = str(content[1])
  message3 = "xxx"
  print(friend)

  for index,item in enumerate(friend):


   print("發送給 "+str(item)+" ing,index="+str(index))
   item.send(message1)
   item.send(message2)
   item.send(message3)

  t = Timer(86400,sendNews)
  t.start()
 except:
  errorMessage = "xxx"
  for index,item in enumerate(friend):
   item.send(errorMessage)


if __name__ == "__main__":
 sendNews()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女