教你用Python感知女友的情緒變化!

導讀

程序員找個對象不容易啊,好不容易有了女友,可相處起來老是磕磕碰碰。python


有時候,你很想關心她,可是你太忙了,以致於她一直抱怨,以爲你不夠關心她。你暗自下決心,下次必定要準時發消息給她,哪怕是幾句話,但是你又忘記了。你以爲本身很委屈😭,可是她又以爲你不負責。linux


如今,再不用擔憂了,用python就能夠給女朋友定時發提示消息了,並且不會漏過每個關鍵時刻,天天早上起牀、中午吃飯、晚上吃飯、晚上睡覺,都會準時發消息給她了,並且還可讓她學習英語單詞哦!git


在生日來臨之時,自動發祝福語。在節日來臨之時,好比三八婦女節、女神節、情人節、春節、聖誕節,自動發問候語哦,不再用擔憂他說你沒有儀式感了😀程序員


最重要的是,能夠實時知道女朋友的情感情緒指數,不再用擔憂女朋友莫名其妙生氣了。github


編寫思路web


爲了方便快速開發,咱們使用python中的wxpy模塊完成微信的基本操做。
json


首先,咱們設置一個config.ini配置文件,並從這個配置文件開始讀取信息。這些參數一看就懂,因此無需多言。windows


↓上下滑動可查看完整內容↓api




# 讀取配置文件微信

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 )----Σ((( つ•̀ω•́)つ----╰(*´︶`*)╯----( ´´ิ∀´ิ` )----(´∩`。)----( ื▿ ื)----(。ŏ_ŏ)----( •ิ _ •ิ )----ヽ(*΄◞ิ౪◟ิ‵ *)----( ˘ ³˘)----(; ´_ゝ`)----(*ˉ﹃ˉ)----(◍ ౪`◍)ノ゙----(。◝‿◜。)----(ಠ .̫.̫ ಠ)----(´◞⊖◟`)----(。≖ˇェˇ≖。)----(◕ܫ◕)----(`◕‸◕´+)----(▼ _ ▼)----( ◉ืൠ◉ื)----ㄟ(◑‿◐ )ㄏ----(● ◡ ●)ノ♥----(。◕ˇ∀ˇ◕)----( ◔ ◔ )----( ´◔ ‸◔`)----(☍﹏⁰)----(♥◠‿◠)----ლ(╹◡╹ლ )----(๑꒪◞౪◟꒪๑)"

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()):

# Windows

bot = Bot()

elif( Darwin in platform.system()):

# MacOSX

bot = Bot()

elif( Linux in platform.system()):

# Linux

bot = Bot(console_qr=2,cache_path=True)

else:

# 自行肯定

print("沒法識別你的操做系統類型,請本身設置")


設置完相關參數之後,咱們再來學習一下,如何天天教女朋友學英語:


# 獲取每日勵志精句

def get_message():

r = requests.get("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( bosonnlp.com/analysis/se… ,data=postData)

data = response.text


# 情感評分指數(越接近1表示心情越好,越接近0表示心情越差)

now_mod_rank = (data.split( , )[0]).replace( [[ , )

print("來自女朋友的消息:%s 當前情感得分:%s 越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿徹底相信! " % (msg.text, now_mod_rank))


# 發送信息到文件傳輸助手

mood_message = u"來自女朋友的消息:" + msg.text + " 當前情感得分:" + now_mod_rank + " 越接近1表示心情越好,越接近0表示心情越差,情感結果僅供參考,請勿徹底相信! "

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安裝下列包:


  • [x] pip install wxpy
  • [x] 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 = 親愛的,生日快樂,我已經給你準備好了禮物哦,明天你就能看到啦!(*@ο@*) 哇~


演示圖片













完整源代碼

github.com/shengqiangz…

別忘記天天多陪陪陪女朋友哈!

關注公衆帳號

飛馬會



往期福利關注飛馬會公衆號,回覆對應關鍵詞打包下載學習資料;回覆「入羣」,加入飛馬網AI、大數據、項目經理學習羣,和優秀的人一塊兒成長!

回覆 數字「1」下載從入門到研究,人工智能領域最值得一讀的10本資料(附下載)

回覆 數字「2」機器學習 & 數據科學必讀的經典書籍,內附資料包!

相關文章
相關標籤/搜索