如何對比多個庫,看看那個最靠譜

wanghui發表於2019-02-16

如何對比多個庫,看看那個最靠譜

思路

  • 用那些參考值
  • 如何獲取資料
  • 如何查詢需要的資料

參考的數值

  • 生態值
  • 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)

相關文章