Github API
Web API
web api是网站的一部分,用于与使用非常具体的URL请求特定信息的程序交互,这种请求被称为API调用。请求的数据将以易于处理的格式(如JSON或CSV)返回;依赖于外部数据源的大多数应用程序都依赖于API调用,如集成社交媒体网站的应用程序。
Github的API
https://api.github.com/search/repositories?q=language:python&sort=stars
第一部分(https://api.github.com/)将请求发送到Github网站响应API调用的部分;search/repositories让API搜索github上所有的仓库,问号指出要传递一个实参,q=开始指定查询,获取语言为Python的仓库的信息,最后一部分指定将项目按其获得的星级排序。如果incomplete_results的值为false,证明请求成功,true代表GitHub无法全面处理该API。
API大多存在速率限制,即在特定时间内执行的请求数存在限制,在浏览器中输入https://api.github.com/rate_limit,可获得GitHub的限制;search表示每分钟限制10个请求,reset值指的是配额将重置的Unix时间或新纪元时间(1970年1月1日午夜后多少秒),注册获得API秘钥之后,配额将高很多。
{
"resources": {
"core": {
"limit": 60,
"remaining": 60,
"reset": 1542466950
},
"search": {
"limit": 10,
"remaining": 10,
"reset": 1542463410
},
"graphql": {
"limit": 0,
"remaining": 0,
"reset": 1542466950
}
},
"rate": {
"limit": 60,
"remaining": 60,
"reset": 1542466950
}
}
--将项目名存储在一个列表中,星级、描述、链接放在一个字典里,使用pygal绘制直方图,每个条形柱会存储一个连接,点击可直接转到所在网页。
hist = pygal.Bar()
hist.add('',plot_dicts)
import requests
import pygal
from pygal.style import LightenStyle as LS,LightColorizedStyle as LCS
#执行API调用,并存储响应,以星级排序
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
#状态码200表示请求成功
print('Status code:',r.status_code)
#将API响应返回的JSON格式的信息转换为一个Python字典
respose_dict = r.json()
print('Total repositories:',respose_dict['total_count'])#一共多少个仓库
#items是一个包含很多字典的列表,每一个字典都包含一个仓库的信息
repo_dicts = respose_dict['items']
#研究第一个仓库
repo_dict = repo_dicts[0]
print('Keys:',len(repo_dict))
print('\nName:',repo_dict['name'])#项目名称
print('Owner:',repo_dict['owner']['login'])#项目所有者登录名
print('Stars:',repo_dict['stargazers_count'])#多少个星的评级
print('Repository:',repo_dict['html_url'])#GitHub仓库的URL
print('Created:',repo_dict['created_at'])#创建时间
print('Updated:',repo_dict['updated_at'])#最后一次更新时间
print('Description:',repo_dict['description'])#打印仓库描述
#2015年GitHub上星级最高的项目,收藏人数16000
for rp_dict in repo_dicts:
if rp_dict['name'] == 'httpie':
#rp_index = repo_dicts.index(rp_dict)
print('\nOwner:', rp_dict['owner']['login'])
print('Stars:', rp_dict['stargazers_count'])
print('Created:', rp_dict['created_at'])
print('Updated:', rp_dict['updated_at'])
#将项目名存储在一个列表中,星级、描述、链接放在一个字典里
names,plot_dicts = [],[]
for r_dict in repo_dicts:
names.append(r_dict['name'])
if r_dict['description']:
plot_dict = {
'value':r_dict['stargazers_count'],
'label':r_dict['description'],
'xlink':r_dict['html_url']
}
plot_dicts.append(plot_dict)
else:
plot_dict = {
'value': r_dict['stargazers_count'],
'label': 'None',
'xlink': r_dict['html_url']
}
plot_dicts.append(plot_dict)
#将GitHub上Python项目的星级和名称可视化
my_style = LS('#119911',base_style=LCS)#指定颜色和样式
#绘制直方图,创建一个Config实例,存储所有的配置
my_config = pygal.Config()
my_config.x_label_rotation = (-45) #x轴标签旋转-45度
my_config.show_legend = False #隐藏图例
my_config.title_font_size = 25 #标题大小
'''
主标签是Y轴上为5000整数倍的刻度,副标签是X轴上的项目
名称和Y轴上的大部分数字,但是显示效果并非如此
'''
my_config.label_font_size = 18 #副标签大小
my_config.major_label_font_size = 30 #主标签大小
#将较长的标签缩短为15个字符,鼠标指向时显示完整名称
my_config.truncate_label = 15
my_config.show_y_guides = False #隐藏图表中的水平线,包括x轴
my_config.width = 1000 #设置图表宽度
hist = pygal.Bar(my_config,style=my_style)
hist.title = 'Most-Popular Python Projects on GitHub'
hist.x_labels = names
hist.add('',plot_dicts)#图例名称为空
hist.render_to_file(r'images\names_stars.svg')
# 直接渲染到浏览器,需要安装lxml
#hist.render_in_browser()
Github API的更多相关文章
- 记一次通过c#运用GraphQL调用Github api
阅读目录 GraphQL是什么 .net下如何运用GraphQL 运用GraphQL调用Github api 结语 一.Graphql是什么 最近在折腾使用Github api做个微信小程序练练手,本 ...
- 关于Homebrew出现GitHub API rate limit错误的解决方法
参考博文: http://havee.me/mac/2013-12/how-to-install-and-use-homebrew.html Error: GitHub API rate limit ...
- 使用 GitHub API 进行数据分析 (Node.js)
使用 GitHub API 进行数据分析 (Node.js) Node.js 的访问 GitHub 的 API 库,通过 npm 或者 yarn 安装: yarn add github-api 官方示 ...
- Github api【Restful接口规范】
Overview This describes the resources that make up the official GitHub REST API v3. If you have any ...
- 从0开始学爬虫10之urllib和requests库与github/api的交互
urllib库的使用 # coding=utf-8 import urllib2 import urllib # htpbin模拟的环境 URL_IP="http://10.11.0.215 ...
- 获取使用GitHub api和Jira api Authentication的方法
近段时间在搭建我司的用例管理平台,有如下需求: 1.需要根据项目--版本--轮次的形式来管理项目用例,用例统一保存在git工程. 2.执行用例时,如果用例执行失败,可以通过平台在Jira上提bug. ...
- 使用GitHub API上传文件及GitHub做图床
本文介绍GitHub API基础及上传文件到仓库API,并应用API将GitHub作为图床 GitHub API官方页面 GitHub API版本 当前版本为v3,官方推荐在请求头中显示添加版本标识. ...
- 博客中gitalk最新评论的获取 github api使用
博客中,对于网友的评论以及每篇文章的评论数还是很重要的.但是基于静态的页面想要存储动态的评论数据是比较难的,一般博客主题中都内置了评论插件,但是博客主题中对于最新评论的支持显示还是很少的,至少目前我是 ...
- GitHub developer API 学习
官网地址:https://developer.github.com/v3/ 目录 当前版本 schema parameters root endpoint client errors http red ...
随机推荐
- 通过 Ansible 创建 Jenkins Server
创建 CI 流程的第一件事应该是安装 CI 工具,本文以最常见的 Jenkins 为例,介绍如何使用 Ansible 自动安装 Jenkins Server.说明:本文的演示环境为 ubuntu 16 ...
- 数据库MongoDB
一.MongoDB简介 MongoDB是由c++语言编写的,是一个基于分布式文件存储的开源数据库系统,在高负载的情况下,添加更多的节点,可以保证服务器性能.MongoDB旨在为web应用提供扩展的高性 ...
- SQL 两个时间获取相差秒数
SELECT DATEDIFF(SECOND, '2005-12-31 23:59:00', '2006-01-01 00:00:00');
- AngularJS+Ionic开发-1.搭建开发环境
临时项目需要使用AngularJS+Ionic+Cordova技术,半年前跟别人用过一段时间做过几个页面,目前别人已经无法联系了,只能我自己上了. 上次做完项目后,想抽时间好好巩固一下这方面的知识面来 ...
- Linux-iconv命令之批处理(18)
iconv命令是用来转换文件的编码方式的,比如它可以将UTF8编码的转换成GB18030的编码,反过来也行 常用选项 -f font1 :(from)将font1型的字符编码进行转换 -t font2 ...
- Ajax提交用FormData()上传文件
1.form声明如下 2.ajax设置如下 var formData = new FormData(document.getElementById("form")); $.ajax ...
- Mybatis 与hibernate
共同点 (1)Hibernate与MyBatis都是通过SessionFactoryBuider由XML配置文件生成SessionFactory,由SessionFactory 生成Session,由 ...
- Apollo源码阅读笔记(二)
Apollo源码阅读笔记(二) 前面 分析了apollo配置设置到Spring的environment的过程,此文继续PropertySourcesProcessor.postProcessBeanF ...
- 表数据量影响MySQL索引选择
现象 新建了一张员工表,插入了少量数据,索引中所有的字段均在where条件出现时,正确走到了idx_nap索引,但是where出现部分自左开始的索引时,却进行全表扫描,与MySQL官方所说的最左匹配原 ...
- HTML5 template元素
前言 转自http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/ 在单页面应用,我们对页面的无刷新有了更高的要求,H ...