日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Python:程序员在每天不同时间发微信消息给女友

發布時間:2025/3/15 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python:程序员在每天不同时间发微信消息给女友 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用python就可以給女友定時發提示消息了,而且不會漏過每一個關鍵時刻,每天早上起床、中午吃飯、晚上吃飯、晚上睡覺,都會準時發消息給她了,而且還可以讓她學習英語單詞哦!

歡迎大家加入小編創建的Python行業交流群,有大牛答疑,有資源共享 有企業招人!是一個非常不錯的交流基地!群號:78486745

在生日來臨之時,自動發祝福語。在節日來臨之時,比如三八婦女節、女神節、情人節、春節、圣誕節,自動發問候語哦,再也不用擔心他說你沒有儀式感了?

最重要的時候,實時可以知道女友的情感情緒指數哦,再也不用擔心女友莫名其妙生氣了。

編寫思路
為了方便快速開發,我們使用python中的wxpy模塊完成微信的基本操作。

首先,,我們設置一個config.ini配置文件,并從這個配置文件開始讀取信息。這些參數一看就懂,所以無需多言。

# 讀取配置文件 cf = configparser.ConfigParser() cf.read("./config.ini",encoding='UTF-8')# 設置女友的微信名稱,記住,不是微信ID也不是微信備注 # 你女友的微信名稱,記住,不是微信ID也不是微信備注 my_lady_wechat_name = cf.get("configuration", "my_lady_wechat_name")# 設置早上起床時間,中午吃飯時間,下午吃飯時間,晚上睡覺時間 say_good_morning = cf.get("configuration", "say_good_morning") say_good_lunch = cf.get("configuration", "say_good_lunch") say_good_dinner = cf.get("configuration", "say_good_dinner") say_good_dream = cf.get("configuration", "say_good_dream")# 設置女友生日信息 # 幾月,注意補全數字,為兩位數,比如6月必須寫成06 birthday_month = cf.get("configuration", "birthday_month") # 幾號,注意補全數字,為兩位數,比如6號必須寫成08 birthday_day = cf.get("configuration", "birthday_day")# 讀取早上起床時間,中午吃飯時間,下午吃飯時間,晚上睡覺時間的隨機提示語 # 一般這里的代碼不要改動,需要增加提示語可以自己打開對應的文件修改 #早上起床問候語列表,數據來源于新浪微博 str_list_good_morning = '' with open("./remind_sentence/sentence_good_morning.txt", "r",encoding='UTF-8') as f:str_list_good_morning = f.readlines() print(str_list_good_morning)#中午吃飯問候語列表,數據來源于新浪微博 str_list_good_lunch = '' with open("./remind_sentence/sentence_good_lunch.txt", "r",encoding='UTF-8') as f:str_list_good_lunch = f.readlines() print(str_list_good_lunch)#晚上吃飯問候語列表,數據來源于新浪微博 str_list_good_dinner = '' with open("./remind_sentence/sentence_good_dinner.txt", "r",encoding='UTF-8') as f:str_list_good_dinner = f.readlines() print(str_list_good_dinner)#晚上睡覺問候語列表,數據來源于新浪微博 str_list_good_dream = '' with open("./remind_sentence/sentence_good_dream.txt", "r",encoding='UTF-8') as f:str_list_good_dream = f.readlines() print(str_list_good_dream)# 設置晚上睡覺問候語是否在原來的基礎上再加上每日學英語精句 # False表示否 True表示是 if((cf.get("configuration", "flag_learn_english")) == '1'):flag_learn_english = True else:flag_learn_english = False print(flag_learn_english)# 設置所有問候語結束是否加上表情符號 # False表示否 True表示是 str_emoj = "(? ̄?? ̄??)??°----(?′ `?)----(?ˉ?ε ˉ??)----(??? ? ???)----( ?? .? ?? )----(?? ??)----(●′ω`●)----(●・??・?●)----?_?----_(:qゝ∠)----(′;ω;`)----( `)3')----Σ((( つ??ω??)つ----╰(*′︶`*)╯----( ′′??′?` )----(′∩`。)----( ?? ?)----(。?_?)----( ?? _ ?? )----ヽ(*??????‵ *)----( ? 3?)----(; ′_ゝ`)----(*ˉ﹃ˉ)----(?'?`?)ノ゙----(。???。)----(? .?.? ?)----(′???`)----(。?ˇェˇ?。)----(???)----(`???′+)----(▼ _ ▼)----( ?????)----ㄟ(??? )ㄏ----(●'?'●)ノ?----(。?ˇ?ˇ?)----( ? ? )----( ′? ??`)----(?﹏?)----(????)----?(???? )----(???????)" str_list_emoj = str_emoj.split('----') if ((cf.get("configuration", "flag_wx_emoj")) == '1'):flag_wx_emoj = True else:flag_wx_emoj = False print(str_list_emoj)# 設置節日祝福語 # 情人節祝福語 str_Valentine = cf.get("configuration", "str_Valentine") print(str_Valentine)# 三八婦女節祝福語 str_Women = cf.get("configuration", "str_Women") print(str_Women)# 平安夜祝福語 str_Christmas_Eve = cf.get("configuration", "str_Christmas_Eve") print(str_Christmas_Eve)# 圣誕節祝福語 str_Christmas = cf.get("configuration", "str_Christmas") print(str_Christmas)# 她生日的時候的祝福語 str_birthday = cf.get("configuration", "str_birthday") print(str_birthday)

如果你愿意,可以在上面對時間的判斷中,加入一些其他你想要的,這樣你女友就更開心啦!后期如果有時間,我將會加上以上節日問候功能。?

接著,開啟微信機器人,為了程序的健壯性,自動判斷一下操作系統,根據不同操作系統執行不同指令

# 啟動微信機器人,自動根據操作系統執行不同的指令 # windows系統或macOS Sierra系統使用bot = Bot() # linux系統或macOS Terminal系統使用bot = Bot(console_qr=2) if('Windows' in platform.system()):# Windowsbot = Bot() elif('Darwin' in platform.system()):# MacOSXbot = Bot() elif('Linux' in platform.system()):# Linuxbot = Bot(console_qr=2,cache_path=True) else:# 自行確定print("無法識別你的操作系統類型,請自己設置")

設置完相關參數以后,我們再來學習一下,如何每天教女友學英語

# 獲取每日勵志精句 def get_message():r = requests.get("http://open.iciba.com/dsapi/")note = r.json()['note']content = r.json()['content']return note,content

只有每天的問候和節日問候是僅僅不夠的,我們必須時刻知道她的情緒指數,這里可以使用snowNlp或者jieba來做分析,但是為了能夠在打包成exe可執行文件時使得程序盡可能小,我們采取直接調用接口的方式來做。代碼如下:

# 接收女友消息監聽器 # 女友微信名 my_girl_friend = bot.friends().search(my_lady_wechat_name)[0] # chats=my_girl_friend 表示接收消息的對象,也就是女友 # except_self=False 表示同時也接收自己發的消息,不需要接收自己消息的可以去掉 @bot.register(chats=my_girl_friend, except_self=False) def print_others(msg):# 輸出聊天內容print(msg.text)# 做極其簡單的情感分析# 結果僅供參考,請勿完全相信postData = {'data':msg.text}response = post('https://bosonnlp.com/analysis/sentiment?analysisType=',data=postData)data = response.text# 情感評分指數(越接近1表示心情越好,越接近0表示心情越差)now_mod_rank = (data.split(',')[0]).replace('[[','')print("來自女友的消息:%s\n當前情感得分:%s\n越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿完全相信!\n\n" % (msg.text, now_mod_rank))# 發送信息到文件傳輸助手mood_message = u"來自女友的消息:" + msg.text + "\n當前情感得分:" + now_mod_rank + "\n越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿完全相信!\n\n"bot.file_helper.send(mood_message)

教完女友學英語后,開始把我們的關心語發給他。這里涉及到wxpy模塊的相關操作,很簡單,看我的例子就會了。

# 發送消息給她 def send_message(your_message):try:# 對方的微信名稱my_friend = bot.friends().search(my_lady_wechat_name)[0]# 發送消息給對方my_friend.send(your_message)except:# 出問題時,發送信息到文件傳輸助手bot.file_helper.send(u"守護女友出問題了,趕緊去看看咋回事~") 最后,就是如何每天定時發關心語給女友的問題了。首先來個while循環,365天無限關心?# 來個死循環,24小時關心她while(True):# 提示print("守護中,時間:%s"% time.ctime())# 每天定時問候,早上起床,中午吃飯,晚上吃飯,晚上睡覺# 獲取時間,只獲取時和分,對應的位置為倒數第13位到倒數第8位now_time = time.ctime()[-13:-8]if (now_time == say_good_morning):# 隨機取一句問候語message = choice(str_list_good_morning)# 是否加上隨機表情if(flag_wx_emoj):message = message + choice(str_list_emoj)send_message(message)print("提醒女友早上起床:%s" % time.ctime())…………這下面還有很多代碼,我就不列出來了…………# 延時60秒time.sleep(60)

最后,輸入以下代碼開始守護女友模式吧~

# 開始守護女友t = Thread(target=start_care, name='start_care')t.start()

使用教程
pip安裝下列包
pip install wxpy
pip install requests
設置以下內容

[configuration]# 設置女友的微信名稱,記住,不是微信ID也不是微信備注 my_lady_wechat_name = 小強子# 設置女友生日信息 # 若某一項月份或者日期不想設置,請輸入99,不能留空 # 幾月,注意補全數字,為兩位數,比如6月必須寫成06 birthday_month = 03 # 幾號,注意補全數字,為兩位數,比如6號必須寫成08 birthday_day = 18# 設置早上起床時間,中午吃飯時間,下午吃飯時間,晚上睡覺時間 # 若某一項時間不想設置,請輸入99:00,不能留空 say_good_morning = 03:09 say_good_lunch = 03:10 say_good_dinner = 03:11 say_good_dream = 03:12# 設置晚上睡覺問候語是否在原來的基礎上再加上每日學英語精句 # 1表示是,0表示否 flag_learn_english = 1# 設置所有問候語結束是否加上表情符號 # 1表示是,0表示否 flag_wx_emoj = 1# 設置節日祝福語 # 情人節祝福語 str_Valentine = 親愛的,情人節快樂!我想和你一起分享生命中的每一天,直到永遠。# 三八婦女節祝福語 str_Women = 嘿,女神節到了,祝我的女神開心快樂!你每天都是那么好看^_^# 平安夜祝福語 str_Christmas_Eve = 寶貝,平安夜快樂,你吃蘋果了嗎?n(*≧▽≦*)n# 圣誕節祝福語 str_Christmas = 小仙女,圣誕節快樂哦!(づ ̄3 ̄)づ╭?~# 她生日的時候的祝福語 str_birthday = 親愛的,生日快樂,我已經給你準備好了禮物哦,明天你就能看到啦!(*@ο@*) 哇~


完整代碼

# -*- coding:utf-8 -*- from __future__ import unicode_literals from wxpy import * from requests import get from requests import post from platform import system from os import chdir from random import choice from threading import Thread import configparser import time import sys# 獲取每日勵志精句 def get_message():r = get("http://open.iciba.com/dsapi/")note = r.json()['note']content = r.json()['content']return note,content# 發送消息給她 def send_message(your_message):try:# 對方的微信名稱my_friend = bot.friends().search(my_lady_wechat_name)[0]# 發送消息給對方my_friend.send(your_message)except:# 出問題時,發送信息到文件傳輸助手bot.file_helper.send(u"守護女友出問題了,趕緊去看看咋回事~")# 在規定時間內進行關心她操作 def start_care():# 待發送的內容,先置為空message = ""# 來個死循環,24小時關心她while(True):# 提示print("守護中,時間:%s"% time.ctime())# 每天定時問候,早上起床,中午吃飯,晚上吃飯,晚上睡覺# 獲取時間,只獲取時和分,對應的位置為倒數第13位到倒數第8位now_time = time.ctime()[-13:-8]if (now_time == say_good_morning):# 隨機取一句問候語message = choice(str_list_good_morning)# 是否加上隨機表情if(flag_wx_emoj):message = message + choice(str_list_emoj)send_message(message)print("提醒女友早上起床:%s" % time.ctime())elif (now_time == say_good_lunch):message = choice(str_list_good_lunch)# 是否加上隨機表情if(flag_wx_emoj):message = message + choice(str_list_emoj)send_message(message)print("提醒女友中午吃飯:%s" % time.ctime())elif (now_time == say_good_dinner):message = choice(str_list_good_dinner)# 是否加上隨機表情if(flag_wx_emoj):message = message + choice(str_list_emoj)send_message(message)print("提醒女友晚上吃飯:%s" % time.ctime())elif (now_time == say_good_dream):# 是否在結尾加上每日學英語if(flag_learn_english):note, content = get_message()message = choice(str_list_good_dream) + "\n\n" + "順便一起來學英語哦:\n" + "原文: " + content + "\n\n翻譯: " + noteelse:message = choice(str_list_good_dream)# 是否加上隨機表情if(flag_wx_emoj):message = message + choice(str_list_emoj)send_message(message)print("提醒女友晚上睡覺:%s" % time.ctime())# 節日問候語festival_month = time.strftime('%m', time.localtime())festival_day = time.strftime('%d', time.localtime())if(festival_month == '02' and festival_day == '14' and now_time == "08:00"):send_message(str_Valentine)print("發送情人節祝福:%s" % time.ctime())elif(festival_month == '03' and festival_day == '08' and now_time == "08:00"):send_message(str_Women)print("發送三八婦女節祝福:%s" % time.ctime())elif(festival_month == '12' and festival_day == '24' and now_time == "00:00"):send_message(str_Christmas_Eve)print("發送平安夜祝福:%s" % time.ctime())elif(festival_month == '12' and festival_day == '25' and now_time == "00:00"):send_message(str_Christmas)print("發送圣誕節祝福:%s" % time.ctime())# 生日問候語if(festival_month == birthday_month and festival_day == birthday_day and now_time == "00:00"):send_message(str_birthday)print("發送生日祝福:%s" % time.ctime())# 每60秒檢測一次time.sleep(60)if __name__ == "__main__":# 若發現讀取取配置文件出錯,可以取消注釋下面這行,一般在pycharm環境下才需要增加# 設置當前文件所在的目錄為當前工作路徑# chdir(sys.path[0])# 啟動微信機器人,自動根據操作系統執行不同的指令# windows系統或macOS Sierra系統使用bot = Bot()# linux系統或macOS Terminal系統使用bot = Bot(console_qr=2)if('Windows' in system()):# Windowsbot = Bot()elif('Darwin' in system()):# MacOSXbot = Bot()elif('Linux' in system()):# Linuxbot = Bot(console_qr=2,cache_path=True)else:# 自行確定print("無法識別你的操作系統類型,請自己設置")# 讀取配置文件cf = configparser.ConfigParser()cf.read("./config.ini",encoding='UTF-8')# 設置女友的微信名稱,記住,不是微信ID也不是微信備注# 你女友的微信名稱,記住,不是微信ID也不是微信備注my_lady_wechat_name = cf.get("configuration", "my_lady_wechat_name")# 設置早上起床時間,中午吃飯時間,下午吃飯時間,晚上睡覺時間say_good_morning = cf.get("configuration", "say_good_morning")say_good_lunch = cf.get("configuration", "say_good_lunch")say_good_dinner = cf.get("configuration", "say_good_dinner")say_good_dream = cf.get("configuration", "say_good_dream")# 設置女友生日信息# 幾月,注意補全數字,為兩位數,比如6月必須寫成06birthday_month = cf.get("configuration", "birthday_month")# 幾號,注意補全數字,為兩位數,比如6號必須寫成08birthday_day = cf.get("configuration", "birthday_day")# 讀取早上起床時間,中午吃飯時間,下午吃飯時間,晚上睡覺時間的隨機提示語# 一般這里的代碼不要改動,需要增加提示語可以自己打開對應的文件修改#早上起床問候語列表,數據來源于新浪微博str_list_good_morning = ''with open("./remind_sentence/sentence_good_morning.txt", "r",encoding='UTF-8') as f:str_list_good_morning = f.readlines()print(str_list_good_morning)#中午吃飯問候語列表,數據來源于新浪微博str_list_good_lunch = ''with open("./remind_sentence/sentence_good_lunch.txt", "r",encoding='UTF-8') as f:str_list_good_lunch = f.readlines()print(str_list_good_lunch)#晚上吃飯問候語列表,數據來源于新浪微博str_list_good_dinner = ''with open("./remind_sentence/sentence_good_dinner.txt", "r",encoding='UTF-8') as f:str_list_good_dinner = f.readlines()print(str_list_good_dinner)#晚上睡覺問候語列表,數據來源于新浪微博str_list_good_dream = ''with open("./remind_sentence/sentence_good_dream.txt", "r",encoding='UTF-8') as f:str_list_good_dream = f.readlines()print(str_list_good_dream)# 設置晚上睡覺問候語是否在原來的基礎上再加上每日學英語精句# False表示否 True表示是if((cf.get("configuration", "flag_learn_english")) == '1'):flag_learn_english = Trueelse:flag_learn_english = Falseprint(flag_learn_english)# 設置所有問候語結束是否加上表情符號# False表示否 True表示是str_emoj = "(? ̄?? ̄??)??°----(?′ `?)----(?ˉ?ε ˉ??)----(??? ? ???)----( ?? .? ?? )----(?? ??)----(●′ω`●)----(●・??・?●)----?_?----_(:qゝ∠)----(′;ω;`)----( `)3')----Σ((( つ??ω??)つ----╰(*′︶`*)╯----( ′′??′?` )----(′∩`。)----( ?? ?)----(。?_?)----( ?? _ ?? )----ヽ(*??????‵ *)----( ? 3?)----(; ′_ゝ`)----(*ˉ﹃ˉ)----(?'?`?)ノ゙----(。???。)----(? .?.? ?)----(′???`)----(。?ˇェˇ?。)----(???)----(`???′+)----(▼ _ ▼)----( ?????)----ㄟ(??? )ㄏ----(●'?'●)ノ?----(。?ˇ?ˇ?)----( ? ? )----( ′? ??`)----(?﹏?)----(????)----?(???? )----(???????)"str_list_emoj = str_emoj.split('----')if ((cf.get("configuration", "flag_wx_emoj")) == '1'):flag_wx_emoj = Trueelse:flag_wx_emoj = Falseprint(str_list_emoj)# 設置節日祝福語# 情人節祝福語str_Valentine = cf.get("configuration", "str_Valentine")print(str_Valentine)# 三八婦女節祝福語str_Women = cf.get("configuration", "str_Women")print(str_Women)# 平安夜祝福語str_Christmas_Eve = cf.get("configuration", "str_Christmas_Eve")print(str_Christmas_Eve)# 圣誕節祝福語str_Christmas = cf.get("configuration", "str_Christmas")print(str_Christmas)# 她生日的時候的祝福語str_birthday = cf.get("configuration", "str_birthday")print(str_birthday)# 開始守護女友t = Thread(target=start_care, name='start_care')t.start()# 接收女友消息監聽器# 女友微信名 my_girl_friend = bot.friends().search(my_lady_wechat_name)[0] @bot.register(chats=my_girl_friend, except_self=False) def print_others(msg):# 輸出聊天內容print(msg.text)# 可采用snownlp或者jieba等進行分詞、情感分析,由于打包后文件體積太大,故暫時不采用這種方式# 僅僅是直接調用網絡接口# 做極其簡單的情感分析# 結果僅供參考,請勿完全相信postData = {'data':msg.text}response = post('https://bosonnlp.com/analysis/sentiment?analysisType=',data=postData)data = response.text# 情感評分指數(越接近1表示心情越好,越接近0表示心情越差)now_mod_rank = (data.split(',')[0]).replace('[[','')print("來自女友的消息:%s\n當前情感得分:%s\n越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿完全相信!\n\n" % (msg.text, now_mod_rank))# 發送信息到文件傳輸助手mood_message = u"來自女友的消息:" + msg.text + "\n當前情感得分:" + now_mod_rank + "\n越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿完全相信!\n\n"bot.file_helper.send(mood_message)

總結

以上是生活随笔為你收集整理的Python:程序员在每天不同时间发微信消息给女友的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。