all repos — myprecious @ 537992b95025dee96ceaf488d003a09bdea99dc4

A lightweight web service to backup precious game saves.

myprecious/utils.py (view raw)

 1from myprecious.encoding import obj_encode
 2import myprecious.constants as c
 3
 4def handle_platform(game, platform):
 5    try:
 6        game_cover = "https:" + game["cover"]["url"]
 7    except KeyError:
 8        game_cover = c.MISSING_COVER_URL
 9    temp_obj = {
10        "game_id": game["id"],
11        "platform_id": platform["id"],
12        "cover": game_cover,
13        "title": game["name"],
14        "platform": platform["name"]
15    }
16    temp_obj["info"] = obj_encode(temp_obj)
17    return temp_obj
18
19def handle_response(response):
20    games = [ [ handle_platform(game, platform) for platform in game["platforms"] ] for game in response ]
21    return collapse_list_of_lists(games)
22
23def collapse_list_of_lists(l):
24    return [ item for sublist in l for item in sublist ]
25
26def parse_remember(form):
27    try:
28        return bool(form["remember"])
29    except KeyError:
30        return False