想跟踪一个github项目,如果该项目更新了,自动打开网页.
import webbrowser
webbrowser.open(url)
github API使用
如何阅读API文档,如何使用
如何利用什么库处理网页内容,提取出自己需要的字段.
使用requests库下载网页, 持续运行while
import requests
all_info = requests.get(api).json()
# requests.get(api),返回的是状态响应码(eg.200), 使用json()转化数据格式为字典
通过字段之间的对比,来判断github项目是否更新了
如果更新了, 就打开网页.
import requests
import webbrowser
import time
api_url = "https://api.github.com/repos/channelcat/sanic"
github_url = "https://github.com/channelcat/sanic"
# get_data -> diff_data -> open url
all_info = requests.get(api_url).json()
old_time = None
# old_time = "2016-06-08T12:30:07Z"
# 为了测试程序,可以先给old_time赋值
while True:
new_time = all_info["updated_at"]
if not old_time:
old_time = all_info["updated_at"]
if new_time > old_time:
old_time = new_time
webbrowser.open(github_url)
time.sleep(100)