17-1其他语言
修改python_repos.py中的API调用,使其生成的图表中显示用其他语言编写的最受欢迎的项目。只需要修改url里的语言信息及图的相关信息即可生成其他语言的直方图。
python_repos.py
import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
# 执行API调用并存储响应
url = 'https://api.github.com/search/repositories?q=language:Java&sort=stars'
r = requests.get(url)
# 状态为200表示访问成功
print("Status code:", r.status_code)
# 将API响应存储在一个变量中
response_dict = r.json()
print("Total repositories:", response_dict['total_count'])
# 探索有关仓库的信息
repo_dicts = response_dict['items']
names, plot_dicts = [], []
for repo_dict in repo_dicts:
names.ap