妙用itchat! python實(shí)現(xiàn)久坐提醒功能
本文實(shí)例為大家分享了python久坐提醒的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
#!/usr/bin/envy python3
#-*- coding:utf-8 -*-
import itchat
import datetime, os, platform,time
def timerfun(sched_time) :
flag = 0
while True:
now = datetime.datetime.now()
if now > sched_time and now < sched_time + datetime.timedelta(seconds=1) : # 因?yàn)闀r(shí)間秒之后的小數(shù)部分不一定相等,要標(biāo)記一個(gè)范圍判斷
send_move()
time.sleep(1) # 每次判斷間隔1s,避免多次觸發(fā)事件
flag = 1
else :
#print('schedual time is {0}'.format(sched_time))
#print('now is {0}'.format(now))
if flag == 1 :
sched_time = sched_time + datetime.timedelta(hours=1) # 把目標(biāo)時(shí)間增加一個(gè)小時(shí),一個(gè)小時(shí)后觸發(fā)再次執(zhí)行
flag = 0
def send_move :
# nickname = input('please input your firends\' nickname : ' )
# 想給誰發(fā)信息,先查找到這個(gè)朋友,name后填微信備注即可,deepin測試成功
# users = itchat.search_friends(name=nickname)
users = itchat.search_friends(name='大壯') # 使用備注名來查找實(shí)際用戶名
#獲取好友全部信息,返回一個(gè)列表,列表內(nèi)是一個(gè)字典
print(users)
#獲取`UserName`,用于發(fā)送消息
userName = users[0]['UserName']
itchat.send("該起來動(dòng)一下了!",toUserName = userName)
print('succeed')
if __name__=='__main__':
itchat.auto_login(hotReload=True) # 首次掃描登錄后后續(xù)自動(dòng)登錄
sched_time = datetime.datetime(2018,7,12,13,24,11) #設(shè)定初次觸發(fā)事件的事件點(diǎn)
print('run the timer task at {0}'.format(sched_time))
timerfun(sched_time)
需要注意的是需要先下載itchat,方法為pip install itchat ,python3.6自帶pip, 只需在scripts目錄下按住shift鼠標(biāo)點(diǎn)擊右鍵即可,運(yùn)行命令即可。
小編再為大家分享一段python代碼,給愛的人設(shè)置喝水提醒功能
import datetime,time
import itchat
def timefun(stoptime):
now=datetime.datetime.now()
gap=datetime.timedelta(hours=1,minutes=30)
#stoptime=datetime.datetime(2018, 12, 11, 18, 00, 00)
if now+gap<stoptime:
sendmessage()
time.sleep(5400)
def sendmessage():
target=itchat.search_friends(name='你的小可愛的名字,記住不是昵稱,是你起得名字哦')
name=target[0]['UserName']
itchat.send("記得喝水哦",toUserName=name)
print('success')
if __name__=='__main__':
itchat.auto_login(hotReload=True)
stoptime=datetime.datetime(2018, 12, 11, 18, 00, 00)
timefun(stoptime)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 利用python實(shí)現(xiàn)短信和電話提醒功能的例子
- 用python寫一個(gè)定時(shí)提醒程序的實(shí)現(xiàn)代碼
- 使用Python實(shí)現(xiàn)微信提醒備忘錄功能
- python自動(dòng)查詢12306余票并發(fā)送郵箱提醒腳本
- python實(shí)現(xiàn)淘寶秒殺聚劃算搶購自動(dòng)提醒源碼
- 利用Python實(shí)現(xiàn)圖書超期提醒
- Python實(shí)現(xiàn)Windows上氣泡提醒效果的方法
- 100行Python代碼實(shí)現(xiàn)每天不同時(shí)間段定時(shí)給女友發(fā)消息
- python每天定時(shí)運(yùn)行某程序代碼
- Python定時(shí)發(fā)送消息的腳本:每天跟你女朋友說晚安
- python愛心表白 每天都是浪漫七夕!
- 教你使用python實(shí)現(xiàn)微信每天給女朋友說晚安
相關(guān)文章
Pyspider進(jìn)行API接口抓取和數(shù)據(jù)采集的實(shí)現(xiàn)
Pyspider是一個(gè)基于Python的強(qiáng)大的網(wǎng)絡(luò)爬蟲框架,它提供了豐富的功能和靈活的擴(kuò)展性,使我們可以輕松地進(jìn)行數(shù)據(jù)的抓取和處理,本文主要介紹了Pyspider進(jìn)行API接口抓取和數(shù)據(jù)采集的實(shí)現(xiàn),感興趣的可以了解一下2023-09-09
Python中用pycurl監(jiān)控http響應(yīng)時(shí)間腳本分享
這篇文章主要介紹了Python中用pycurl監(jiān)控http響應(yīng)時(shí)間腳本分享,本文腳本實(shí)現(xiàn)監(jiān)控http相應(yīng)碼,響應(yīng)大小,建立連接時(shí)間,準(zhǔn)備傳輸時(shí)間,傳輸?shù)谝粋€(gè)字節(jié)時(shí)間,完成時(shí)間,需要的朋友可以參考下2015-02-02
Python計(jì)算不規(guī)則圖形面積算法實(shí)現(xiàn)解析
這篇文章主要介紹了Python計(jì)算不規(guī)則圖形面積算法實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11
Python?操作?MongoDB數(shù)據(jù)庫的方法(非?ODM)
這篇文章主要介紹了Python?操作?MongoDB?----非?ODM的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
python實(shí)現(xiàn)MD5進(jìn)行文件去重的示例代碼
工作中偶爾會收到一大堆文件,名稱各不相同,分析文件的時(shí)候發(fā)現(xiàn)有不少重復(fù)的文件,導(dǎo)致工作效率低下,那么,這里就寫了一個(gè)python腳本實(shí)現(xiàn)文件去重功能,感興趣的就一起來了解一下2021-07-07

