Beispiel #1
0
def get_user_stats(user_id):
    try:
        data = generate(str(user_id))
    except ParserError as e:
        app.logger.error(u'Parser error: ' + e.msg)
        flash(u"Problème lors de la récupération des données: " + e.msg,
              'alert-error')
        abort(500)
    except:
        app.logger.error(u'Fatal error')
        flash(u"Une erreur s'est produite", 'alert-error')
        abort(500)

    # jsonify uses indent=None for XMLHttpRequest
    resp = jsonify(**data)
    resp.headers['Cache-Control'] = 'max-age=86400,must-revalidate'
    return resp
Beispiel #2
0
def data():
    locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))
    filename = os.path.join(DATA_DIR, '113594.1.json')
    with codecs.open(filename, "r", "utf-8") as f:
        content = f.read()

    HTTPretty.register_uri(HTTPretty.GET, URL + '/page/1', body=content,
                           content_type="application/json")

    filename = os.path.join(DATA_DIR, '113594.2.json')
    with codecs.open(filename, "r", "utf-8") as f:
        content = f.read()

    HTTPretty.register_uri(HTTPretty.GET, URL + '/page/2', body=content,
                           content_type="application/json")

    filename = os.path.join(DATA_DIR, '113594.3.json')
    with codecs.open(filename, "r", "utf-8") as f:
        content = f.read()

    HTTPretty.register_uri(HTTPretty.GET, URL + '/page/3', body=content,
                           content_type="application/json")

    return generate(113594)