def api_get_all_meta():
    json_res = get_all_meta_json()
    ret = Response(json_res, mimetype='text/json')
    ret.content_encoding = 'utf-8'
    ret.headers.set("Cache-Control", "public, max-age=604800")

    return ret
def api_get_class1():
    out_list = list()
    for row in get_class1():
        out_list.append(row[0])

    ret = Response(json.dumps(out_list, ensure_ascii=False), mimetype='text/json')
    ret.content_encoding = 'utf-8'
    ret.headers.set("Cache-Control", "public, max-age=604800")

    return ret
Beispiel #3
0
def get_today_signal():
    res = get_all_signals()
    req = list()
    for i in res:
        print(i)
        req.append(i)
    req = json.dumps(req)
    resp = Response(req)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    resp.mimetype = 'application/json'
    resp.content_encoding = 'UTF-8'
    return resp
Beispiel #4
0
def tarball(family, name, version, filename):
    # this will not work in production
    # nginx will stop it

    root = current_app.config["WWW_ROOT"]
    fpath = os.path.join(root, "repository", family, name, version, filename)
    if not os.path.exists(fpath):
        return abortify(404)
    ctype, encoding = mimetypes.guess_type(filename)
    if not ctype:
        ctype = "text/html"
    with open(fpath, "rb") as f:
        data = f.read()
        resp = Response(data, content_type=ctype)
        if encoding:
            resp.content_encoding = encoding
        return resp
Beispiel #5
0
def tarball(family, name, version, filename):
    # this will not work in production
    # nginx will stop it

    root = current_app.config['WWW_ROOT']
    fpath = os.path.join(root, 'repository', family, name, version, filename)
    if not os.path.exists(fpath):
        return abortify(404)
    ctype, encoding = mimetypes.guess_type(filename)
    if not ctype:
        ctype = 'text/html'
    with open(fpath, 'rb') as f:
        data = f.read()
        resp = Response(data, content_type=ctype)
        if encoding:
            resp.content_encoding = encoding
        return resp
Beispiel #6
0
def get_msg():
    data = get_last_signals()
    print(data)
    req = list()
    for k, v in data.items():
        list_of_files = glob.glob(config.UPLOAD_FOLDER + '/*')
        img = max(list_of_files, key=os.path.getctime)
        img = img.split('/')[-1]
        req.append({**dev_message[k], "img": img, **v})
        insert_alert_to_database(dev_message[k]['head'],
                                 dev_message[k]['body'], img)
    req = json.dumps(req)
    resp = Response(req)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    resp.mimetype = 'application/json'
    resp.content_encoding = 'UTF-8'
    return resp
Beispiel #7
0
def get_msg():
    data = get_last_signals()
    print(data)
    req = list()
    for i in data:
        list_of_files = glob.glob(config.UPLOAD_FOLDER + '/*')
        img = max(list_of_files, key=os.path.getctime)
        img = img.split('/')[-1]
        req.append({
            "head": "Вы устали!",
            "body": "Рекомендуется устроить небольшой перерыв",
            "img": img,
            "id": 1,
            "level": "danger"
        })
        insert_alert_to_database('Вы устали',
                                 'Рекомендуется устроить небольшой перерыв',
                                 img)
    req = json.dumps(req)
    resp = Response(req)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    resp.mimetype = 'application/json'
    resp.content_encoding = 'UTF-8'
    return resp
def make_response(dictionary, id=None):
    if id:
        dictionary["id"] = id
    ret = Response(json.dumps(dictionary, ensure_ascii=False), mimetype='text/json')
    ret.content_encoding = 'utf-8'
    return ret