# 设置早上起床时间,中午吃饭时间,下午吃饭时间,晚上睡觉时间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.readlinesprint(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.readlinesprint(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.readlinesprint(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.readlinesprint(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')----Σ((( つ•̀ω•́)つ----╰(*´︶`*)╯----( ´´ิ∀´ิ` )----(´∩`。)----( ื▿ ื)----(。ŏ_ŏ)----( •ิ _ •ิ )----ヽ(*΄◞ิ౪◟ิ‵ *)----( ˘ ³˘)----(; ´_ゝ`)----(*ˉ﹃ˉ)----(◍'౪`◍)ノ゙----(。◝‿◜。)----(ಠ .̫.̫ ಠ)----(´◞⊖◟`)----(。≖ˇェˇ≖。)----(◕ܫ◕)----(`◕‸◕´+)----(▼ _ ▼)----( ◉ืൠ◉ื)----ㄟ(◑‿◐ )ㄏ----(●'◡'●)ノ♥----(。◕ˇ∀ˇ◕)----( ◔ ڼ ◔ )----( ´◔ ‸◔`)----(☍﹏⁰)----(♥◠‿◠)----ლ(╹◡╹ლ )----(๑꒪◞౪◟꒪๑)"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)
如果你愿意,可以在上面对时间的判断中,加入一些其他你想要的,这样你女友就更开心啦!后期如果有时间,我将会加上以上节日问候功能。 😀
接着,开启微信机器人,为了程序的健壮性,自动判断一下操作系统,根据不同操作系统执行不同指令
# 启动微信机器人,自动根据操作系统执行不同的指令# windows系统或macOS Sierra系统使用bot = Bot# linux系统或macOS Terminal系统使用bot = Bot(console_qr=2)if('Windows'inplatform.system):# Windowsbot = Botelif('Darwin'inplatform.system):# MacOSXbot = Botelif('Linux'inplatform.system):# Linuxbot = Bot(console_qr=2,cache_path=True)else:# 自行确定print("无法识别你的操作系统类型,请自己设置")
设置完相关参数以后,我们再来学习一下
# 获取每日励志精句defget_message:r = requests.get("http://open.iciba.com/dsapi/")note = r.json['note']content = r.json['content']returnnote,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)defprint_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("来自女友的消息:%sn当前情感得分:%sn越接近1表示心情越好,越接近0表示心情越差,情感结果仅供参考,请勿完全相信!nn"% (msg.text, now_mod_rank))
# 发送信息到文件传输助手mood_message = u"来自女友的消息:"+ msg.text + "n当前情感得分:"+ now_mod_rank + "n越接近1表示心情越好,越接近0表示心情越差,情感结果仅供参考,请勿完全相信!nn"bot.file_helper.send(mood_message)
教完女友学英语后,开始把我们的关心语发给他。这里涉及到wxpy模块的相关操作,很简单,看我的例子就会了。
# 发送消息给她defsend_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)
最后,输入以下代码开始守护女友模式吧~