示例#1
0
def searchplatforms(request):
    result = igdb.platforms({
        'filters': {
            "[name][eq]": "PC (Microsoft Windows)",
        },
        'order': ["name:asc"],
        'fields': ['name'],
    })

    platforms = result.body

    result = igdb.platforms({
        'filters': {
            "[generation][eq]": 7,
        },
        'order': ["name:asc"],
        'fields': ['name'],
    })

    platforms += result.body

    result = igdb.platforms({
        'filters': {
            "[generation][eq]": 8,
        },
        'order': ["name:asc"],
        'fields': ['name'],
    })

    platforms += result.body
    return HttpResponse(json.dumps({
        'status': "success",
        'platforms': platforms
    }),
                        content_type="application/json")
示例#2
0
def get_platforms(platform_name):

    result = igdb.platforms({
        'search': platform_name,
        'fields': ["games", "name"]
    })
    return result
示例#3
0
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)
示例#4
0
def get_all_games():
    """Makes API calls to get game information"""

    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
    ]
    # get the list of games per platform
    systems_json = igdb.platforms({'ids': platforms, 'fields': 'games'})
    # dump the data into a file
    with open('systemsfile2.json', 'w') as fp:
        json.dump(systems_json, fp)

    for platform_id in platforms:
        # loop through each platform and get the game info
        game_ids = igdb.platforms({
            'ids': platform_id,
            'fields': ['games', 'name']
        })[0]["games"]

        num_games = len(game_ids)

        num_iterations = (num_games / 1000) + 1
        fields = [
            'id', 'name', 'genres', 'storyline', 'summary', 'cover',
            'screenshots', 'videos'
        ]

        for i in range(num_iterations):

            platform_games = igdb.games({
                'ids':
                game_ids[i * 1000:i * 1000 + 1000],
                'fields': [
                    'id', 'name', 'genres', 'storyline', 'summary', 'cover',
                    'screenshots', 'videos'
                ]
            })
        with open('testfile' + str(platform_id) + '.json', 'w') as fp:
            json.dump(platform_games, fp)
示例#5
0
def get_platforms():
    global igdb
    i = 0
    platforms = []
    result = igdb.platforms({
        'filters': {
            '[generation][gt]': 7
        },
    })
    for info in result.body:
        platforms.append(info)
    return platforms
示例#6
0
def get_platforms_flask():
    global igdb
    platforms = []
    result = igdb.platforms({
        'filters': {
            '[generation][gt]': 7
        },
    })
    for info in result.body:
        plat_name = info['name']
        plat_id = info['id']
        platforms.append({'name': plat_name, 'id': plat_id})
    return platforms
示例#7
0
def get_platform_info():
    print("Getting Platform Data...")

    result = igdb.platforms({
        'fields':["name", "id", "summary", "alternative_name", "generation"],
        'scroll':1,
        'limit':50
    })
    list_of_platforms = []
    xcount = result.headers["X-Count"]
    timestoscroll = (math.ceil((int(xcount)) / 50)) - 1
    for x in range(timestoscroll):
        for y in result.body:
            empty_dict = {}
            try:
                empty_dict["id"] = y["id"]
            except:
                empty_dict["id"] = ""
            try:
                empty_dict["name"] = y["name"]
            except:
                empty_dict["name"] = ""
            try:
                empty_dict["alternative_name"] = y["alternative_name"]
            except:
                empty_dict["alternative_name"] = ""
            try:
                empty_dict["generation"] = y["generation"]
            except:
                empty_dict["generation"] = ""
            try:
                empty_dict["summary"] = y["summary"]
            except:
                empty_dict["summary"] = ""
            list_of_platforms.append(empty_dict)
        result = igdb.scroll(result)
    # loaded_json = json.loads(newresult.text)
    dumped_json = json.dumps(list_of_platforms, indent = 4)
    fw = open(platform_cache,"w")
    fw.write(dumped_json)
    fw.close()
    CACHE_DICTION["platform_time"] = time.strftime("%a %b %d %H:%M:%S %Y")
    dumped_json = json.dumps(CACHE_DICTION, indent = 4)
    fw = open(CACHE_FNAME,"w")
    fw.write(dumped_json)
    fw.close()
    def handle(self, *args, **options):
        from igdb_api_python.igdb import igdb
        igdb = igdb('0cc499afcdb8b8076835350cd909f9f1')
        result = igdb.platforms({
            'ids': '6',
            'fields': 'games'
        })
        games = ast.literal_eval(result.content)
        games = [str(g) for g in games[0]['games']]

        i = 0
        content = []
        while i < 1000:
            result = igdb.games({
                'ids': games[i + 1:min(i + 1000, 23769)],
                'fields': ['name', 'first_release_date', 'url', 'cover', 'summary'],
            })
            content += (ast.literal_eval(result.content))
            i += 1000

        Game.objects.all().delete()
        for game in content:
            try:
                game['year'] = convert_release_date(game['first_release_date'])
                g = Game(id=game['id'], name=game['name'], year=game['year'], url = game['url'])
            except KeyError:
                g = Game(id=game['id'], name=game['name'], url = game['url'])
            try:
                if game['cover']['url'][0] == 'h':
                    g.cover_url = game['cover']['url'].replace('t_thumb','t_cover_big')
                else:
                    g.cover_url = 'https:' + game['cover']['url'].replace('t_thumb','t_cover_big')

            except KeyError:
                pass
            try:
                g.summary=game['summary']
            except KeyError:
                pass
            g.save()
示例#9
0
def add_platform_filter(game_name, platform_name):

    result = igdb.games({'search': game_name, 'fields': ['name']})
    filter = igdb.platforms({'search': platform_name, 'filter': ['name']})
# -*- coding: utf-8 -*-

from igdb_api_python.igdb import igdb

igdb = igdb("c00b1bbc30c379f30337f726be119a69")
import json
import os

#ids_list = [130, 87,99,33,22,19,58,21,4,5,159,20,37,41,137,18,24] #nintendo
#ids_list = [7, 8, 38, 46, 48, 9] #sony
#ids_list = [12, 11, 49] #microsoft
# ids_list = [64, 29, 78, 35, 30, 32, 23] #sega

platform_names = open('platform_names.txt', 'w')

ids = [
    130, 87, 99, 33, 22, 19, 58, 21, 4, 5, 159, 20, 37, 41, 137, 18, 24, 7, 8,
    38, 46, 48, 9, 12, 11, 49, 64, 29, 78, 35, 30, 32, 23, 6
]
for id in ids:

    result = igdb.platforms({'ids': id, 'fields': 'name'})
    platform_names.write(result.body[0]['name'] + ' ' + str(id) + '\n')

platform_names.close()
示例#11
0
import json
from igdb_api_python.igdb import igdb as igdb
import time, os
import pymongo
from pymongo import MongoClient

client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.gameDB
games = db.platforms
#ENTER YOUR KEY HERE
igdb = igdb('a5b58ad9a031a212726ac14390047c4f')
data = {}
a = 149  ## La lista va en el #4899
for i in range(3):
    id_list = []
    b = a + 50
    for j in range(a, b):
        id_list.append(j)
    result = igdb.platforms({
        'fields': ['name'],  #no se incluyo el summary
        'limit': 50,
        'ids': id_list
    })
    print(result.body)
    for game in result.body:
        print(game)
        games.insert(game)

    a += 50
示例#12
0
from igdb_api_python.igdb import igdb

igdb = igdb("c00b1bbc30c379f30337f726be119a69")
import json
import os

#ids_list = [130, 87,99,33,22,19,58,21,4,5,159,20,37,41,137,18,24] #nintendo
#ids_list = [7, 8, 38, 46, 48, 9] #sony
#ids_list = [12, 11, 49] #microsoft
ids_list = [64, 29, 78, 35, 30, 32, 23]  #sega

for id in ids_list:
    result = igdb.platforms({
        # 'ids':[130, 87,99,33,22,19,58,21,4,5,159,20,37,41,137,18,24],
        'ids': [id],
        'fields': ['games', 'name']
    })

    platform_name = result.body[0]['name']

    if not os.path.exists(str('games_json/' + platform_name)):
        os.makedirs(str('games_json/' + platform_name))

    games_id = result.body[0]['games']
    for i in range(0, len(games_id), 100):

        result = igdb.games({'ids': games_id[i:i + 100]})

        for game in result.body:
            game_json = open(