2019-01-28 17:53:26 +01:00

42 lines
1.3 KiB
Python

import psycopg2
import config
from flask import Flask, render_template
from pprint import pprint
import os
app = Flask(__name__)
app.debug = True
sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt","permission","content" FROM "Notes" ORDER BY "lastchangeAt" DESC;'
@app.route("/")
def main():
DB_HOST = os.environ.get('DB_HOST')
DB_NAME = os.environ.get('POSTGRES_DB')
DB_USER = os.environ.get('POSTGRES_USER')
DB_PASSWORD = os.environ.get('POSTGRES_PASSWORD')
try:
conn = psycopg2.connect(host=DB_HOST, database=DB_NAME, user=DB_USER,
password=DB_PASSWORD)
cur = conn.cursor()
cur.execute(sql_statement)
notes = cur.fetchall()
pprint(notes)
print("NOTES LEN", len(notes))
cur.close()
conn.close()
notes_arr = []
for note in notes:
notes_arr.append(
{'id': note[0], 'title': note[1], 'alias': note[2], 'shortid': note[3], 'viewcount': note[4],
'lastchangeAt': note[5], 'permission': note[6], 'content': note[7]})
return render_template('index.html', notes=notes_arr, host=config.CODI_URL)
except Exception as e:
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)