程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Send new year 00:00 blessings in python (directly on New Years Eve!)

編輯:Python

2022 The new year is coming , Here we use Python Write a string of simple code to send blessings to all partners in wechat at a fixed point !!

Environmental statement

Python edition : There is no limit

Third party Library : itchat, schedule

notes : All the blessings come from the Internet , The code runs for a long time , Better run on the server

The code is as follows

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 18-12-9 In the morning 9:08
# @Author : KainHuck
# @Email : [email protected]
# @File : New year's Day blessing .py
import itchat
import random
import schedule
import datetime
import time
# Sign in , And temporarily save the login status
itchat.auto_login(hotReload=True)
# Get all your friends information friends = itchat.get_friends(update=True)
# Filter out friends without comment names , And put the friends who want to send blessings in a dictionary
final_friends = {}
for each in friends:
if len(each['RemarkName']) > 0:
final_friends[each['RemarkName']] = each['UserName']
# List of blessings
greeting = [' It's new year's day , In the days of leaving the old and welcoming the new , I would like to send away your troubles and welcome happiness , Send off pressure and welcome health , Seeing off frustrated ushered in a smooth , Seeing off the accident ushers in peace , And hope you have a happy New Year's Day .', ' A round dream , Colorful flowers ; A round life , Colorful paintings ; Round new year's day , Happy home ; Round greetings , The cause is booming ; Round blessing , You laugh ! I wish you a happy New Year's day ! ', ' New year's Day is coming , Information cannot be late ; Friends come to check in , Blessings are delivered in advance : Love is romantic and beautiful , Friendship is warm , Family affection always revolves around , Work performance is rising , Life is happy and joyful , The coming year will be better ! ', ' Joy , Rippling in my heart ; Smile , On the cheeks ; singing , In the melodious reverberation ; A dance step , Walking in comfort ; fireworks display , In full bloom ; blessing , Sending frequently . friend , Happy New Year's Day ! I wish you happiness , A happy family ! ', ' New year's day with blessings , Happy new year ; Try harder on New Year's day , Good results in the new year ; New year's day plus you , A good awesome in the new year ! I wish you a beautiful new year's day , Happy for a whole century !', ' A new beginning, a new hope , New day, new sunshine , Start a new pursuit , Sow new dreams , Turn to a new page , Write down the new glory . A new year begins , Send you deep blessing , Happy New Year's Day .', ' New year's day will come , I thought hard . Good friends , Give me something . I don't have much money , I didn't win the lottery . Send blessings via SMS , Courtesy is less than affection . I wish you peace of mind , Happy New Year's day !', ' Turn happiness into SMS , Send it to you , Wish you a happy New Year ; Integrate good luck into information , Pass it on to you , May the New Year be , Good luck and happiness go on ; On New Year's day, I will copy all my blessings , One is concurrent with you , May everything go well for you next year ! ']
# Send blessing function
def send_greet(RemarkName,userName):
greet = random.choice(greeting) # Choose a blessing at random
message = RemarkName + ',' + greet # Add a comment name
itchat.send(message, toUserName=userName)
# Define the task
def job():
now_date = str(datetime.datetime.now().date()) # Get the time when the function executes
if now_date == '2019-01-01' or now_date == '2019-1-1': # If it is 2019 On the new year's day of the year (PS: forget datetime.datetime.now().date() Output format ...)
for each_friend in final_friends:
send_greet(each_friend, final_friends['final_friends'])
# Every day 00:00 Do it once job function
schedule.every().day.at("00:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved