如何对比多个库,看看那个最靠谱

思路

  • 用那些参考值
  • 如何获取数据
  • 如何查询需要的数据

参考的数值

  • 生态值
  • star数
  • Fork数

如何获取数据

https://api.github.com/search/repositories?q=django
https://api.github.com/search/repositories?q=bottle
https://api.github.com/search/repositories?q=flask
  • 事例:
https://api.github.com/search/repositories?q=django&sort=stars&order=asc

查询数据

  • input函数即可

开始搞

  • postman请求: https://api.github.com/search/repositories?q=bottle

查生态的api接口

https://api.github.com/search/repositories?q=topic.django

写代码

# API:
'''
以django为例:
https://api.github.com/search/repositories?q=django
https://api.github.com/search/repositories?q=topic:django   #生态
'''
import requests

def get_names():
    print('Separate each name with Space')
    names = input()
    return names.split()

def check_repos(names):
    repo_api = "https://api.github.com/search/repositories?q="
    ecosys_api = "https://api.github.com/search/repositories?q=topic:"
    for name in names:
        ecosys_info = requests.get(ecosys_api+name).json()['total_count']
        repo_info = requests.get(repo_api+name).json()['items'][0]
        stars = repo_info['stargazers_count']
        forks = repo_info['forks_count']

        print('Stars:'+str(stars))
        print('Forks:'+str(forks))
        print('Ecosys:'+str(ecosys_info))
        print("--------------------")

name = get_names()
check_repos(name)

wanghui
34 声望9 粉丝