示例#1
0
def get_data(user_id, max_age=DEF_MAX_AGE):
    if user_id < 100000000:
        raise APIError(1457)
    jsonf, age = get_cache(INFO_CACHE_DIR, "%d.json" % user_id,
                           lambda f: load_info(user_id, f), max_age=max_age)
    mtime = os.stat(jsonf).st_mtime
    with open(jsonf) as fd:
        data = json.load(fd)

    if data["data_headers"]["result_code"] != 1:
        raise APIError(data["data_headers"]["result_code"])
    if "data" not in data:
        raise Exception("No data returned")

    return ProducerInfo(data), mtime
示例#2
0
def load_snap(snap):
    try:
        snap = str(snap)
    except:
        abort(404)
    if len(str(snap)) != 16:
        abort(404)
    try:
        base64.b64decode(snap, "-_")
    except:
        abort(404)

    jsonf, age = get_cache(SNAPSHOT_DIR, "%s.json" % snap, lambda p: abort(404))
    with open(jsonf) as fd:
        data = ProducerInfo.from_json(fd.read())
    return data
示例#3
0
        w, h = im.size
        if fac == 1:
            return im
        elif fac > 1:
            return im.resize((w // fac, h // fac), Image.BICUBIC)
        elif fac == -1:
            return im.crop((0, 0, h, h))
        elif fac == -2:
            im = im.resize((w // 2, h // 2), Image.BICUBIC)
            w, h = im.size
            new_im = Image.open('twitter_bg.png')
            new_w, new_h = new_im.size
            new_im.paste(im, ((new_w - w) // 2, (new_h - h) // 2), im)
            return new_im

    data_err = ProducerInfo.from_json(open("error.json").read())
    data_404 = ProducerInfo.from_json(open("error_404.json").read())
    data_503 = ProducerInfo.from_json(open("error_503.json").read())
    for fac in (1, 2, 3, 4, -2, -1):
        im = render_banner(data_503, mgr)
        im = scale(im, fac)
        im.save("static/error_503_%d.png" % fac)

        im = render_banner(data_404, mgr)
        im = scale(im, fac)
        im.save("static/error_404_%d.png" % fac)

        im = render_banner(data_err, mgr)
        im = scale(im, fac)
        im.save("static/error_%d.png" % fac)