2021-03-04 10:23:21 -05:00
|
|
|
from flask import Flask
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2021-03-15 17:33:18 -04:00
|
|
|
import json
|
|
|
|
import sqlite3
|
|
|
|
import os
|
|
|
|
DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
|
|
|
|
|
2021-03-04 10:23:21 -05:00
|
|
|
@app.route('/')
|
|
|
|
def hello_world():
|
2021-03-17 02:33:12 -04:00
|
|
|
return 'Hello from backend!'
|
2021-03-15 17:33:18 -04:00
|
|
|
|
|
|
|
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
|
2021-03-04 10:23:21 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run(debug=True)
|