From 24f7dd79a66769b7a72970f17aee8f2afac580de Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 12 Jul 2020 21:37:37 +0530 Subject: Added v1 API --- Procfile | 3 ++- api.py | 40 ++++++++++++++++++++++++++++++++++++++++ app/__init__.py | 2 +- requirements.txt | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 api.py diff --git a/Procfile b/Procfile index 2ac01f7..a3e8f20 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ -web: gunicorn -w 4 -b "0.0.0.0:$PORT" app:app \ No newline at end of file +# web: gunicorn -w 4 -b "0.0.0.0:$PORT" app:app +web: gunicorn -w 4 api:app -k uvicorn.workers.UvicornWorker -b "0.0.0.0:$PORT" diff --git a/api.py b/api.py new file mode 100644 index 0000000..436f6fe --- /dev/null +++ b/api.py @@ -0,0 +1,40 @@ +from app import app as flask_app +#app.run(debug=True, host="0.0.0.0", port=8080) + +from fastapi import Body,FastAPI +from fastapi.middleware.wsgi import WSGIMiddleware +from flask import Flask, escape, request +from pydantic import BaseModel + +import mysql.connector as con +mycon = con.connect(host=flask_app.config['DB_HOST'],user=flask_app.config['DB_USER'],password=flask_app.config['DB_PASSWORD'],port=flask_app.config['DB_PORT'],database=flask_app.config['DB_NAME']) +mycursor = mycon.cursor() + +""" +@flask_app.route("/") +def flask_main(): + name = request.args.get("name", "World") + return f"Hello, {escape(name)} from Flask!" +""" + +app = FastAPI() + + +@app.get("/v1") +def API_Version(): + return {"message":"Curie-API v1"} + + + +@app.get("/v1/status/{job_id}") +def get_status(job_id: str): + sqlQuery = 'select id, protein_name, ligand_name, date, description, done from curieweb where id="%s"' % (job_id) + mycursor.execute(sqlQuery) + records = mycursor.fetchall() + if records == []: + return {"message":"Invalid Job ID"} + r = records[0] + return {"job_id":r[0],"Protein Name":r[1],"Ligand Name":r[2],"Submitted On":r[3],"Job Description":r[4],"Job Status":r[5]} + + +app.mount("/", WSGIMiddleware(flask_app)) \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index 95312c5..8c32ef4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,7 +3,7 @@ from flask import Flask # Config Values # location where file uploads will be stored UPLOAD_FOLDER = './app/static/uploads' -DB_HOST = '192.168.1.6' #'navanspi.duckdns.org' +DB_HOST = 'navanspi.duckdns.org' #'navanspi.duckdns.org' DB_PORT = 3306 DB_USER = 'curieweb' DB_PASSWORD = 'curie-web-russian-54' diff --git a/requirements.txt b/requirements.txt index 3c45d1a..1f17149 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Jinja2==2.11.0 MarkupSafe==1.1.1 Werkzeug==0.16.1 WTForms==2.2.1 +fastapi==0.59.0 tabulate untangle mysql_connector -- cgit v1.2.3