Esempio n. 1
0
def fetch_game(publisher_id, game_tag, filestore):
    """
    Fetches a game zip from mochiads and extracts its content to disk
    
    @type publisher_id: string
    @param publisher_id: Your mochiads Publisherid  
    
    @type game_tag: string
    @param game_tag: the game_tag of the game to fetch
    
    @type filestore: string
    @param filestore: A directory to extract the game content 
    """
    full_url = __MOCHI_FEED + publisher_id + '/'+game_tag + __MOCHI_FEED_FORMAT_SUFFIX
    response = urllib2.urlopen(full_url)
    game_info =json.load(response)
    game = Game(game_info['games'][0]) 
    downloaded = __download(game.zip_url, store_location = filestore)
    if not downloaded:
        return None
    zipfile_name = filestore + game.get_zip_filename()
    game_zip = ZipFile(zipfile_name)
    if not check_mochi_zip(game_zip, game):
        game_zip.close()
        os.remove(zipfile_name)
        return None
    
    if sys.version_info < (2, 6):
        __extract_zip(game_zip, filestore)
    else:
        game_zip.extractall(filestore)

    game_zip.close()
    os.remove(zipfile_name)
    return get_game(filestore, slug=game.slug)
Esempio n. 2
0
def view_game(request, **kwargs):
    slug = kwargs['slug']
    game = get_game(mediastore, slug=slug)
    return Response(render_game(game))