Python程序员的乐子
2018-02-23 本文已影响0人
DonkeyJason
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 = 0
print('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 = 0
print('This programe started on' + time.ctime())
while (break_count < total_breaks):
time.sleep(60*60*30) #半小时提醒一次
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