From 3139b527af9a7692038a0336c93574a4976694a1 Mon Sep 17 00:00:00 2001 From: assar Date: Fri, 2 Jun 2017 14:42:29 +0000 Subject: [PATCH] Added query API URL and initializing of the DB --- server.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.py b/server.py index eac9afa..386b540 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,6 @@ import json import sqlalchemy +from sqlalchemy.sql import select from flask import Flask from flask import render_template @@ -7,11 +8,16 @@ app = Flask(__name__) db_engine = {} db_metadata = {} +parts = {} @app.route('/') def index(): return render_template('partsearch.html') +@app.route('/query/') +def query(query): + pass + def connect(user, password, db, host='localhost', port=5432): '''Returns a connection and a metadata object''' # We connect with the help of the PostgreSQL URL @@ -30,4 +36,9 @@ if __name__ == '__main__': with open('admin.json') as f: postgres_credentials = json.load(f) db_engine, db_metadata = connect(postgres_credentials['username'], postgres_credentials['password'], 'parts') + parts = sqlalchemy.Table('parts', db_metadata) + # Example query + '''s = select([parts]).where(parts.c.notes != '') + for row in db_engine.execute(s): + print row''' app.run('0.0.0.0')