プログラマーの遠距離恋愛は、もちろんチャットロボットで解決しますよ


十数年前、筆者が今の妻と知り合ったばかりの頃、私はまだ大洋の向こうのアメリカで働いていたことを覚えています.当時、通信手段が不便で、アメリカと中国の時は関係が遠く、毎日チャットできる時間が少なかったので、自動チャットロボットを作って、思いを和らげるしかありませんでした.
当時私はまだCSDNのWINDOWS MOBILE区の版主で、しかも当時微信はまだ張小龍に作られていなかったことを覚えています.私たちは最も多くのチャットツールを使っていたのはMSNかモバイルの飛信で、当時モバイルオペレーティングシステムの覇者ノキアのSymbianはまだ解読注入をサポートしていませんでした.そのため、当时このロボットはWINDOWS MOBILEの中でフック(HOOK)をサポートできる机种しか使えませんでしたが、そのスマートフォンが流行していなかった时代には、その难易度は非常に大きく、当时のWINDOWS MOBILE版内の皆さんが力を合わせて、チャットロボットを完成させてくれたシーンを今でも覚えています.残念なことに、当時のフォーラムの投稿はもう見つかりませんでした.残ったのはCSDNの最初のブログ「windows mobileからメモリカードにインストール」(https://blog.csdn.net/BEYONDMA/article/details/3281386)と5編目のブログ『WINCEのフック』(https://blog.csdn.net/BEYONDMA/article/details/3281437)当時の思い出を少し記録しています.
これは私がCSDNで書いた100番目のブログで、私が選択問題に頭を働かせている間に、GithubのPythonトッププロジェクトexamples-of-web-crawlers(https://github.com/shengqiangzhang/examples-of-web-crawlers)これは多くの爬虫類の例で、その中にはちょうど「毎日異なる時間帯に微信で彼女にメッセージを送る」というモジュールがあります.現在、Pythonを使って簡単なチャットロボットを作るのは以前のWINDOWS MOBILEよりずっと簡単ですが、100編目のブログとして、このGithubのPythonのチャットロボットを紹介します.昔の青春を記念しましょう.
チャットロボットを運転する前の準備
1.まず、wxpyとrequestsをインストールするには、次のコマンドを使用します.

pip install wxpy
pip install requests

   2.

github https://github.com/shengqiangzhang/examples-of-web-crawlers/tree/master/4.%E6%AF%8F%E5%A4%A9%E4%B8%8D%E5%90%8C%E6%97%B6%E9%97%B4%E6%AE%B5%E9%80%9A%E8%BF%87%E5%BE%AE%E4%BF%A1%E5%8F%91%E6%B6%88%E6%81%AF%E6%8F%90%E9%86%92%E5%A5%B3%E5%8F%8B

3.

  config.ini

1095 :


 birthday_month =              , 3     03

1121 :


 birthday_month =              , 3     03

     1129 :  


birthday_day =              , 8     08

4. :

windows pycharm say_to_lady.py 146 。


#chdir(sys.path[0])

5. :

, , , , 。


            ,           ,           〒_〒      ,           ~
        :        11  ,       %10   。    ***      ,     、           。
       !
                   。
  ,       。

-》 wxpy Bot -》 -》 。 , , :


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) + "

" + " :
" + " : " + content + "

: " + note else: 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__": # , # windows macOS Sierra bot = Bot() # linux macOS Terminal bot = Bot(console_qr=2) if ('Windows' in system()): # Windows bot = Bot() elif ('Darwin' in system()): # MacOSX bot = Bot() elif ('Linux' in system()): # Linux bot = 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 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) # 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
:%s
1 , 0 , , !

" % (msg.text, now_mod_rank)) # mood_message = u" :" + msg.text + "
:" + now_mod_rank + "
1 , 0 , , !

" bot.file_helper.send(mood_message)

 

PythonIDE , , , Python ,


Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as beyondma

, wxpy , , “pass_ticket” , , 。