用Github的Api发现stars最多开源项目
来源:互联网 发布:笑郭网络验证4.0破解 编辑:程序博客网 时间:2024/05/22 05:27
Github的API无需注册,在网上可以查到使用信息和一些限制:
查询的请求为每分钟10次
此次用到的api格式如下:
url = ‘https://api.github.com/search/repositories?q=language:python&sort=stars’
/search/repositories 搜索github上的仓库
?传递一个查询参数q,=指定查询的内容language:python,查询语言为python的仓库信息
&sort=stars项目按照获得的星星数量排名
倒入用到的库
import requests
# 获取最受欢迎的前30个仓库的信息,返回对象为一个字典对象def get_info(language): url = 'https://api.github.com/search/repositories?q=language:%s&sort=stars'%(language) r = requests.get(url) if r.status_code == 200: print 'success' return r.json()
# 获取python,java,C++三种语言最受欢迎的库response_python = get_info('python')response_java = get_info('java')response_c_dplus = get_info('C++')
successsuccesssuccess
获取信息函数返回字典对象的键值
print (response_python.keys())
[u’total_count’, u’items’, u’incomplete_results’]response_java['total_count'] # github上java语言仓库的数量
3453199response_python['items'][0].keys() # item包含仓库的一些详细信息的列表
[u'issues_url', u'deployments_url', u'stargazers_count', u'forks_url', u'mirror_url', u'subscription_url', u'notifications_url', u'collaborators_url', ........ u'watchers', u'name', u'language', u'url', u'created_at', u'pushed_at', u'forks_count', u'default_branch', u'teams_url', u'trees_url', u'branches_url', u'subscribers_url', u'stargazers_url']
incomplete_results,在执行更复杂的Api调用是,需要检查它的结果.简单的调用可以忽略
对字典对象进行处理,生成一个DataFrame对象
# 返回一个dataframe对象import pandas as pddef ret_df(response_dict): df = pd.DataFrame(columns=['created_at','updated_at','name','forks' ,'stars','size']) for resp_dict in response_dict['items']: df = df.append({ 'created_at':resp_dict['created_at'], 'updated_at':resp_dict['updated_at'], 'name':resp_dict['name'], 'forks':resp_dict['forks'], 'stars':resp_dict['stargazers_count'], 'size':resp_dict['size']},ignore_index=True) return df
Python语言前5个最受欢迎的仓库可视化仓库
# pygal对仓库信息进行可视化import pygal
# 生成数据df_python = ret_df(response_python)df_java = ret_df(response_java)df_c_dplus = ret_df(response_c_dplus)
每个仓库的stars和forks
def show(df, language): line_chart = pygal.Line(x_label_rotation=45) line_chart.title = 'Most-Starred %s projects on Github'%language line_chart.x_labels = df['name'] line_chart.add('forks',df['forks']) line_chart.add('stars',df['stars']) line_chart.render_to_file(language+'_projects.svg')
show(df_c_dplus, 'C++')
不同语言的比较
# 不同语言比较from pygal.style import TurquoiseStyledef compare_show(df_py,df_j,df_c, colu): chart = pygal.Bar() chart.title = 'Compare different language' chart.x_labels = range(1,31) # 项目星星排名 chart.add('Python', df_py[colu]) chart.add('Java', df_j[colu]) chart.add('C++', df_c[colu]) chart.render_to_file(colu+'.svg')
compare_show(df_python, df_java, df_c_dplus, 'stars')
阅读全文
0 0
- 用Github的Api发现stars最多开源项目
- Github上Stars最多的53个深度学习项目
- 2016年度GitHub上Stars最多的项目
- 2016年度GitHub上Stars最多的项目
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先(转)
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先
- 2016年度GitHub上Stars最多的10个Python项目
- Github上Stars超过1000的优秀开源项目推荐(值得收藏)
- 如何在 Github 上发现优秀的开源项目?
- 如何在GitHub上发现优秀的开源项目
- 如何在 Github 上发现优秀的开源项目
- 如何在 Github 上发现优秀的开源项目?
- 如何在 Github 上发现优秀的开源项目?
- mysql安装 赋权限
- JQuery对象与dom对象的转化
- 悼念512汶川大地震遇难同胞
- 将博客搬至CSDN
- AMD INSTINCT
- 用Github的Api发现stars最多开源项目
- try{}catch(Exception e){}异常处理
- Stanford CoreNLP学习日记2
- “SIM卡状态”中的dBm和状态栏的信号格数是对应的吗?
- Java线程:锁
- lnmp环境的使用
- Java线程:堵塞队列与堵塞栈
- Hdu 6069
- pick定理