updatedb.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:game_recommendations 作者: ceorourke 项目源码 文件源码
def check_for_new_games():
    """Make an API call and compare new games with existing db"""

    platforms = [130, 48, 49, 37, 46, 41, 5, 47, 56, 4, 21, 19, 18, 58, 20, 22, 33, 24,
            87, 7, 8, 9, 38, 45, 11, 12, 36, 92, 14, 6, 13, 64, 29, 35, 32, 23, 34,
            39, 86, 51, 15, 13 ,79, 80, 119, 120, 135, 136]
    to_add = {}
    # get the new list of games per platform
    systems_json = igdb.platforms({
        'ids':platforms,
        'fields' : 'games'
    })

    print type(systems_json[0])
    # get the existing list of games per platform
    existing_file = open('seed_data/systemsfile2.json')
    existing = existing_file.read()
    existing = json.loads(existing)
    # compare this list to the existing list
    for system in systems_json:
        for existing_systems in existing:
            if system['id'] == existing_systems['id']:
                for game in system['games']:
                    if game not in existing_systems['games']:
                        if system['id'] in to_add:
                            to_add[system['id']].append(game)
                        else:
                            to_add[system['id']] = [game]
            else:
                print "No differences"


    get_new_games(to_add)
    existing_file.close()
    # overwrite the old file with the new information
    with open('seed_data/systemsfile2.json', 'w') as fp:
            json.dump(systems_json, fp)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号