以前寫過一遍,pyhton結合圖靈機器人自動回覆,以前51cto是使用網頁簽到,可是已經失效了,微信簽到的原理和以前的機器人差很少的,不過是使用了python的itchat模塊,結合定時功能,自動簽到。python
python3
pip install itchat pip install apscheduler
#!/usr/bin/env python # -*- coding:utf-8 -*- """ @author:Aiker Zhao @file:sign_51cto.py @time:下午12:06 """ import itchat import json from apscheduler.schedulers.blocking import BlockingScheduler itchat.auto_login(enableCmdQR=0, hotReload=True) # windows下使用enableCmdQR=0,linux命令行使用enableCmdQR=2 # 獲取好友列表,調用此方法後可獲得好友列表 my_mps = itchat.get_mps() # friends = itchat.get_friends() # 咱們能夠使用json庫將好友列表轉換成json格式 # print(json.dumps(friends)) # print(json.dumps(my_mps)) ''' # 暫時不用舊的函數 def job(): mps = itchat.search_mps(name=u'51CTO')[0] mps.send(u'簽到') mps.send(u'下載豆') ''' def qiandao(): info_51cto = itchat.search_mps('51CTO') if info_51cto: username_51cto = info_51cto[0].get('UserName') itchat.send(u'簽到', username_51cto) itchat.send(u'下載豆', username_51cto) #qiandao() def job_heartbeat(): info_51cto = itchat.search_mps(name=u'51CTO')[0] print('1') sched = BlockingScheduler() #sched = BlockingScheduler(timezone="UTC") # 若是報timezone不一致的錯誤,須要指定timezone # sched.add_job(job, 'interval', hours=24) sched.add_job(qiandao, 'cron', hour=16, minute=19, second=22) sched.add_job(job_heartbeat, 'interval', minutes=1) sched.start()
def job(): u51cto = itchat.search_mps(name=u'51CTO') if u51cto: mps = u51cto[0] mps.send(u'簽到') mps.send(u'下載豆')
def qiandao(): info_51cto = itchat.search_mps('51CTO') if info_51cto: username_51cto = info_51cto[0].get('UserName') itchat.send(u'簽到', username_51cto) itchat.send(u'下載豆', username_51cto)
心得:能夠在雲主機上後臺運行,掃碼登陸便可linux