note:版本v1
- 項目描述:
- 用python實現自動提醒休息
- 此處我用瀏覽器中的三個MV視頻作爲提醒
環境:
- python3.5
- win10
- webbrowser模塊
- time模塊
- sys模塊
代碼如下:
#!/usr/bin/env python #-*- coding:UTF-8 -*- import sys import webbrowser import time sys.path.append("libs")
total_breaks = 3
break_count = 0print('This programe started on' + time.ctime()) while (break_count < total_breaks): time.sleep(2*60*60) #兩個小時提醒一次 url1 = 'http://v.yinyuetai.com/video/3161181' url2 ='http://v.yinyuetai.com/video/3158917?vid=3161181' url3 = 'http://v.yinyuetai.com/video/3157203?vid=3161181' if break_count < 1: webbrowser.open(url1) elif break_count < 2: webbrowser.open(url2) else: webbrowser.open(url3) print (webbrowser.get()) break_count +=1
note:版本v2
更新:
- 1.用指定瀏覽器打開網頁
- 2.定時打開並且定時關閉
提示:
- 1.windows命令:taskkill /F /IM iexplore.exe(
- 關閉程序方法—os.system(‘taskkill /F /IM iexplore.exe’))
- 2.linux 命令是:killall(kill不建議使用) /F /IM qq.exe
- ( #linux中:os.system(‘killall /F /IM qq.exe’)
import sys
import webbrowser
import time
import os
sys.path.append(“libs”)total_breaks = 3
break_count = 0
off = 0print(‘This programe started on’ + time.ctime())
while (break_count < total_breaks):
time.sleep(30*60) #半小時提醒一次
url1 = ‘http://v.yinyuetai.com/video/3161181’
url2 =’http://v.yinyuetai.com/video/3158917?vid=3161181’
url3 = ‘http://v.yinyuetai.com/video/3157203?vid=3161181’
IEPath = r’C:/Program Files/Internet Explorer/iexplore.exe’ # 例如我的:C:/Program Files/Internet Explorer/iexplore.exe
webbrowser.register(‘IE’, None,
webbrowser.BackgroundBrowser(IEPath)) # 這裏的’IE’可以用其它任意名字,如IE11,這裏將想打開的瀏覽器保存到’IE’if break_count < 1: webbrowser.get('IE').open(url1, new=1, autoraise=True) time.sleep(2*60) #播放兩分鐘停止 os.system('taskkill /F /IM iexplore.exe') off +=1 elif break_count < 2 and off > 0: webbrowser.get('IE').open(url2, new=1, autoraise=True) time.sleep(2 * 60) os.system('taskkill /F /IM iexplore.exe') off +=1 elif off > 1: webbrowser.get('IE').open(url3, new=1, autoraise=True) time.sleep(2 * 60) os.system('taskkill /F /IM iexplore.exe') off += 1 print (webbrowser.get()) break_count +=1
- 1.windows命令:taskkill /F /IM iexplore.exe(