我正在使用GitHub API绘制最受关注的项目。这是代码:
import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
path = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(path)
r_py = r.json()
repo_dicts = r_py['items']
names, plot_dicts = [], []
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
attr = {
'stars' : repo_dict['stargazers_count'],
'description' : repo_dict['description'] or "",
'link' : repo_dict['html_url'],
}
plot_dicts.append(attr)
chart = pygal.Bar(x_label_rotation=45, show_legend=False)
chart.x_labels = names
chart.add('', plot_dicts)
chart.title = 'Most popular Python Projects on GitHub'
chart.render_to_file('PopPy.svg')
当我运行渲染的文件(PopPy.svg
)时,它显示以下图表,没有数据:
我仔细检查了API,看看是否对字典使用了错误的密钥。一切似乎都是正确的,但仍然无法按预期进行。
请帮助我,谢谢。