Esempio n. 1
0
 def post():
     data = request.json
     res = jsonpify(createUserProgress(data))
     res.status_code = 201
     return res
Esempio n. 2
0
 def get():
     user = request.args["u"]
     uid = request.args["uid"]
     res = jsonpify(getUserProgress(user, uid))
     res.status_code = 200
     return res
Esempio n. 3
0
def get_document_handler(doc_id):
    result = get_document('document', doc_id)
    if result is None:
        logging.warning('Failed to fetch document for %r', doc_id)
        raise NotFound()
    return jsonpify(result)
Esempio n. 4
0
 def get():
     res = jsonpify(getContent())
     res.status_code = 200
     return res
Esempio n. 5
0
def api_cells_unitcells_cif_fetch():
    global apiVersion
    global cellsDBPath
    global cellsDBSchema
    data_dict = json.loads(request.data)
    url_param = data_dict["url"]
    unitcell_link = None
    status = None
    data = {}
    try:
        base_url = urllib.parse.urlparse(url_param)
        self_url = urllib.parse.urlparse(request.host_url)
        if base_url.netloc == self_url.netloc:
            return redirect(url_param, code=301)

        base = os.path.basename(base_url.path)
        base_filename = os.path.splitext(base)[0]
        base_extension = os.path.splitext(base)[1]
        base_filename_with_ext = base_filename + base_extension
        if base_extension == ".html":
            base_url = base_url._replace(
                path=str(os.path.splitext(base_url.path)[0] + ".cif"))
            base_filename_with_ext = base_filename + ".cif"

        cif_file = urllib.request.urlopen(base_url.geturl())
        with open(base_filename_with_ext, 'wb') as output:
            output.write(cif_file.read())

        cell = ase.io.read(base_filename_with_ext)
        os.remove(base_filename_with_ext)

        data = prepare_cif_json(cell)
        inserted_cell_id = save_cells_unitcells_data(None, data, cellsDBPath,
                                                     cellsDBSchema)
        unitcell_link = "{0}api/cells/unitcells/{1}".format(
            request.host_url, inserted_cell_id)
        status = True

    except ValueError as e:
        print(e)

    return_code = 404
    result = None
    if status is None:
        result = {
            "apiVersion": apiVersion,
            "params": request.args,
            "method": request.method,
            "took": 0,
            "error": {
                "code": 404,
                "message": "Something went wrong.",
                "url": request.url,
            },
        }
        return_code = 404
    else:
        result = {
            "apiVersion": apiVersion,
            "params": request.args,
            "method": request.method,
            "took": 0,
            "data": data,
            "links": {
                "cell": {
                    "unitcell": unitcell_link
                }
            },
        }
        return_code = 200

    return jsonpify(result), return_code