python 调用github的api,呈现python的受欢迎的程度

本文介绍如何使用Python调用GitHub API获取并分析Python项目的受欢迎程度。通过requests库进行API请求,获取到仓库信息如项目名称、拥有者、星数等,并使用pygal进行数据可视化,展示Python项目的热度。同时,文章还讨论了API速率限制及其处理方法,以及如何改进pygal图表以添加自定义工具提示。
摘要由CSDN通过智能技术生成

1 使用api调用数据:

 在浏览器的地址栏中输入:

https://api.github.com/search/repositories?q=language:python&sort=starts

 这个api调用github当前托管的python项目

{
  "total_count": 3872430,
  "incomplete_results": true,
  "items": [
    {
      "id": 21289110,
      "node_id": "MDEwOlJlcG9zaXRvcnkyMTI4OTExMA==",
      "name": "awesome-python",
      "full_name": "vinta/awesome-python",
      "private": false,
---snip----

"total_count":  github上共有的python项目

"incomplete_results": true, 表示请求成功,如果github无法处理该api他返回的值是true

"items"python项目的具体的信息

2 安装requests,

requests 可以让python程序轻松向网站请求信息以及检查返回的响应

pip install --user requests

代表仅该用户的安装,安装后仅该用户可用。处于安全考虑,尽量使用该命令进行安装。

3 简单的处理api的响应

import requests
url = 'https://api.github.com/search/repositories?q=language:python&sort=starts'
r = requests.get(url)

# 打印出状态码
print('status code',r.status_code)
# status code 200 转态码 200表示成功

response_dict = r.json()

#  打印出所有的keys
print(response_dict.keys())
# dict_keys(['total_count', 'incomplete_results', 'items'])

 

 4仓库的信息

仓库的信息:

{
      "id": 21289110,
      "node_id": "MDEwOlJlcG9zaXRvcnkyMTI4OTExMA==",
      "name": "awesome-python",
      "full_name": "vinta/awesome-python",
      "private": false,
      "owner": {
        "login": "vinta",
        "id": 652070,
        "node_id": "MDQ6VXNlcjY1MjA3MA==",
        "avatar_url": "https://avatars2.githubusercontent.com/u/652070?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/vinta",
        "html_url": "https://github.com/vinta",
        "followers_url": "https://api.github.com/users/vinta/followers",
        "following_url": "https://api.github.com/users/vinta/following{/other_user}",
        "gists_url": "https://api.github.com/users/vinta/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/vinta/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/vinta/subscriptions",
        "organizations_url": "https://api.github.com/users/vinta/orgs",
        "repos_url": "https://api.github.com/users/vinta/repos",
        "events_url": "https://api.github.com/users/vinta/events{/privacy}"
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值