美文网首页
快速比较多个库的有缺点

快速比较多个库的有缺点

作者: Oneshot_fea8 | 来源:发表于2019-01-11 21:27 被阅读0次
    # 目的:对比多个库看哪个更靠谱
    
    # https://api.github.com/search/repositories?q=django
    # https://api.github.com/search/repositories?q=topic:django
    
    # get_names -- check_repos两大步骤按照面向过程的方法形成两个函数
    import requests
    
    
    # 返回的就是一个列表,装满了所有被分割的字符串
    def get_names():
        print('Seprate each 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:
            # 简单的字符串拼接获得完全的网址
            repo_info = requests.get(repo_api+name).json()['items'][0]
            # 1/json --2/dict -- 3/dict['items'] -- list[0] -- django {name:django,star:123}
            # 分别找star和fork数
            stars = repo_info['stargazers_count']
            forks = repo_info['forks_count']
            # 获取该库的生态
            ecosys_info = requests.get(ecosys_api+name).json()['total_count']
            # 全部展先出来,注意相同类型才能实现字符串相加
            print(name)
            print('Stars:'+str(stars))
            print('Forks:'+str(forks))
            print('Ecosys:'+str(ecosys_info))
            print('----------')
    
    names = get_names()
    check_repos(names)  
    
    运行结果:
    Seprate each with space
    flask django sanic bottle
    flask
    Stars:41170
    Forks:11816
    Ecosys:8973
    ----------
    django
    Stars:38771
    Forks:16725
    Ecosys:12885
    ----------
    sanic
    Stars:11095
    Forks:1055
    Ecosys:199
    ----------
    bottle
    Stars:5929
    Forks:1183
    Ecosys:142
    ----------  
    

    相关文章

      网友评论

          本文标题:快速比较多个库的有缺点

          本文链接:https://www.haomeiwen.com/subject/twufdqtx.html