Added query API URL and initializing of the DB

master
assar 8 years ago
parent 9f6937296b
commit 3139b527af

@ -1,5 +1,6 @@
import json import json
import sqlalchemy import sqlalchemy
from sqlalchemy.sql import select
from flask import Flask from flask import Flask
from flask import render_template from flask import render_template
@ -7,11 +8,16 @@ app = Flask(__name__)
db_engine = {} db_engine = {}
db_metadata = {} db_metadata = {}
parts = {}
@app.route('/') @app.route('/')
def index(): def index():
return render_template('partsearch.html') return render_template('partsearch.html')
@app.route('/query/<query>')
def query(query):
pass
def connect(user, password, db, host='localhost', port=5432): def connect(user, password, db, host='localhost', port=5432):
'''Returns a connection and a metadata object''' '''Returns a connection and a metadata object'''
# We connect with the help of the PostgreSQL URL # We connect with the help of the PostgreSQL URL
@ -30,4 +36,9 @@ if __name__ == '__main__':
with open('admin.json') as f: with open('admin.json') as f:
postgres_credentials = json.load(f) postgres_credentials = json.load(f)
db_engine, db_metadata = connect(postgres_credentials['username'], postgres_credentials['password'], 'parts') 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') app.run('0.0.0.0')

Loading…
Cancel
Save