diff --git a/backend/main.py b/backend/main.py index 0f45f9d..49e23da 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,9 +1,30 @@ from flask import Flask app = Flask(__name__) +import json +import sqlite3 +import os +DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db') + @app.route('/') def hello_world(): return 'Hello, World!' + +def regen_JSON(): + """Gets links from DB and outputs them in JSON""" + con = sqlite3.connect(DB_PATH) + con.row_factory = sqlite3.Row + cur = con.cursor() + cur.execute('SELECT url, name FROM links ORDER BY position') + + links_list = [] + for row in cur.fetchall(): + d = dict(zip(row.keys(), row)) + links_list.append(d) + links_json = json.dumps(links_list, indent=4) + + con.close() + return links_json if __name__ == "__main__": app.run(debug=True) \ No newline at end of file