Ai
1 Star 0 Fork 0

leetone/my_python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
python_repos.py 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
import requests
import 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: "+ str(r.status_code))
#将响应结果存储在json里面
response_dict = r.json()
#print(response_dict.keys())
#探索有关仓库的信息
repo_dicts = response_dict['items']
# print("Repositories :" ,len(repo_dicts))
#研究第一个仓库
repo_dict = repo_dicts[0]
print('项目名:'+repo_dict['name'])
print('所有者:'+repo_dict['owner']['login'])
print('加星数:',repo_dict['stargazers_count'])
print('仓库链接:'+repo_dict['html_url'])
print('创建时间:'+repo_dict['created_at'])
print('更新时间:'+repo_dict['updated_at'])
print('描述:'+repo_dict['description'])
names,plot_dicts = [],[]
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
description = '暂无描述'
if repo_dict['description']:
description = repo_dict['description']
plot_dict = {
'value': repo_dict['stargazers_count'],
'label': description,
'xlink': repo_dict['html_url'],
}
plot_dicts.append(plot_dict)
#可视化
my_style = LS('#333366',base_style=LCS)
#自定义配置
my_config = pygal.Config()
my_config.x_label_rotation = 45 # x轴坐标倾斜45度
my_config.show_legend = False
my_config.title_font_size = 24
my_config.label_font_size = 14
my_config.major_label_font_size = 18
my_config.truncate_label = 15
my_config.show_y_guides = False #不展示图标中的水平虚线
my_config.width = 1000
chart = pygal.Bar(my_config,style=my_style)
chart.title = 'GitHub上的最受欢迎的Python项目'
chart.x_labels = names
chart.add('',plot_dicts)
chart.render_to_file('python_repos.svg')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/leetone123/my_python.git
git@gitee.com:leetone123/my_python.git
leetone123
my_python
my_python
master

搜索帮助