SoFunction
Updated on 2024-11-21

python3+pyqt5+itchat wechat timed message sending method

This program is to make up this program is wanted for the holidays over the New Year, some important anniversary, to relatives and friends to send blessings and so on, but to 0:00 a.m. to appear more sincere, but I'm more sleepy, often forgetting, so there is a WeChat timer to send a message small program.

Running environment:

python , python2 is not supported.

preliminary

Since I'm using WeChat's interface, I'm introducing itchat.

The interface uses pyqt5

The installation commands are as follows:

pip install PyQt5
pip install itchat

code section

# -*- coding: utf-8 -*-
# @Time  : 2018/9/25 11:06
# @Author : Tangweeiyang
# @File  : 

from  import *
from  import *
from  import QIcon,QFont
import sys
import datetime
import time
import itchat
import threading
from tkinter import messagebox

class FriendsList(QThread):
  sinOut = pyqtSignal(str)
  # Custom signal, emitted from the thread in question when the run() function is executed.

  def __init__(self):
    super().__init__()

  def run(self):

    itchat.auto_login(hotReload=True)
    friendList = itchat.get_friends()
    for each in friendList:
      if len(each['RemarkName']) < 2: #If the comment name is empty, use the WeChat nickname.
        (each['NickName'])
      else:
        (each['RemarkName'])

class sendMessage(QThread):

  def __init__(self,message,name,time):
    super().__init__()
    =message
    =name
    =time

  def run(self):
    timer = (,)
    ()

  def send(self):

    itchat.auto_login(hotReload=True)
    sender = itchat.search_friends()[0]['UserName']
    (, toUserName=sender)
    (, toUserName='filehelper')
    ('Message','Sent successfully')


class weixinSender(QListWidget):

  def __init__(self):
    super().__init__()
    ()
    # ()

  def Ui(self):
    self.year_label = QLabel('Year')
    =QLineEdit()
    self.month_label=QLabel('Moon')
    =QLineEdit()
    self.day_label=QLabel('Day')
    =QLineEdit()
    self.friendList_lable=QLabel('Friends')
    =QComboBox()

    self.hour_label = QLabel('Time')
     = QLineEdit()
    self.min_label = QLabel('Points')
     = QLineEdit()
    self.second_label = QLabel('Seconds')
     = QLineEdit()

    =QTextEdit() #Text field
     = QPushButton('Get Friends List')
    =QPushButton('Sent periodically')


    grid = QGridLayout()
    (10) # Create space between tags

    (self.year_label,1,1)
    (,1,0)
    (self.month_label,1,3)
    (,1,2)
    (self.day_label,1,5)
    (,1,4)
    (self.friendList_lable,1,6,2,1)
    (,1,7,2,3)

    (self.hour_label,2,1)
    (,2,0)
    (self.min_label,2,3)
    (,2,2)
    (self.second_label,2,5)
    (,2,4)

    (,3,0,4,10)
    (,7,5,1,2)
    (,7,7,1,2)

    (grid)

    ('Friend 1')
    ('Friend 2')

    (QFont("Italics.",12,))

    ()
    ()
    (300, 300, 500, 300)
    ('Send messages regularly')
    (QIcon('')) #Window Icons
    ()

  def dataProduce(self):
    now=()
    (str(now.tm_year))
    (str(now.tm_mon))
    (str(now.tm_mday))
    (str(now.tm_hour))
    (str(now.tm_min))
    (str(now.tm_sec))

    ()
    =FriendsList()
    ()
    ()

  def slotAdd(self,name):
    (name)

  def send(self):
     = (int(()),int(()),int(()),int(()),int(()),int(()))
     = ()
    self.delay_time = () - 
    =sendMessage((),(),self.delay_time)
    ()

if __name__ == '__main__':
  app = QApplication()
  ex = weixinSender()
  (app.exec_())

operating procedure

1. After copying and pasting the code, run, the interface as shown (you can change the icon in the program to your favorite picture)

python3+pyqt5+itchat微信定时发送消息

2. point to get a list of friends button, the first time will pop up the WeChat web version of the QR code to log in (the second run, itchat will record your log in records, just click on your cell phone WeChat to confirm the log in button), with the cell phone WeChat scanning log in can be. The time box will show the current time, you can change the set time to send (if the agreed time has passed, the message will be sent immediately), in the friends of the drop-down list to select the friend you want to send (if the friend has a note, it will show the note, otherwise it will show the WeChat nicknames), in the following text box to enter the message you want to send, currently only supports text, does not support the picture!

In the last step, click on the Send regularly button and wait for your friend to receive the message, and I set the file assistant will also receive this message, but you can also delete it.

Final rendering

python3+pyqt5+itchat微信定时发送消息

The above this python3+pyqt5+itchat wechat timed to send a message is all I have to share with you, I hope to be able to give you a reference, and I hope you will support me more.