Unix_time = response_dict[‘resources’][‘search’][‘reset’]
#转换为咱看的明白的时间
China_time = datetime.datetime.fromtimestamp(Unix_time)
print(“每分钟最多可以执行的请求数量:”,response_dict[‘resources’][‘search’][‘limit’])
print(“当前这一分钟内还可以执行的请求数量:”,response_dict[‘resources’][‘search’][‘remaining’])
print(“配额将重置的时间:”,China_time)

(4)使用Pygal可视化仓库:
创建一个交互式条形图:条形的高度表示项目获得了多少颗星。单击条形将带你进入项目在GitHub上的主页!
import requests
import pygal
引入要应用于图表的Pygal样式
from pygal.style import LightColorizedStyle as LCS,LightenStyle as LS
#执行API调用并存储相应
url = ‘https://api.github.com/search/repositories?q=language:python&sort=stars’
r = requests.get(url)
print(“Status code:”,r.status_code)
#将API响应存储在一个变量中
response_dict = r.json()
total_count表示GitHub总共有多少个Python项目
print(“Total repositories:”,response_dict[‘total_count’])
#探索有关仓库的信息
与items相关联的值是一个列表,其中包含很多字典,而每个字典都包含有关一个Python仓库的信息。
repo_dicts = response_dict[‘items’]
#研究第一个仓库
repo_dict = repo_dicts[0]
存储项目名以及相应项目获得的星数
names,stars = [],[]
for repo_dict in repo_dicts:
names.append(repo_dict[‘name’])
stars.append(repo_dict[‘stargazers_count’])
#可视化
#定义一个样式:基色设置为深蓝色;传递实参base_style,以使用LightColorizedStyle类
my_style = LS(‘#333366’,base_styl
最低0.47元/天 解锁文章
348

被折叠的 条评论
为什么被折叠?



