Add endpoint to list all attributes (for editor to consume)
This commit is contained in:
parent
9efdb8fdbf
commit
7389e555fe
|
@ -1,22 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"url": "http://csclub.uwaterloo.ca/",
|
|
||||||
"name": "CS Club Website"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://www.instagram.com/uwcsclub/",
|
|
||||||
"name": "Instagram"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://www.facebook.com/uw.computerscienceclub",
|
|
||||||
"name": "Facebook"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "http://twitch.tv/uwcsclub",
|
|
||||||
"name": "Twitch"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "http://bit.ly/uwcsclub-yt",
|
|
||||||
"name": "YouTube"
|
|
||||||
}
|
|
||||||
]
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask, request
|
from flask import Flask, request, jsonify
|
||||||
from flask_httpauth import HTTPBasicAuth
|
from flask_httpauth import HTTPBasicAuth
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
import json
|
import json
|
||||||
|
@ -9,12 +9,8 @@ DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
auth = HTTPBasicAuth()
|
auth = HTTPBasicAuth()
|
||||||
|
|
||||||
f = open("password.txt","r")
|
|
||||||
pwd = f.readline().rstrip("\n")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
users = {
|
users = {
|
||||||
"admin": generate_password_hash(pwd),
|
"admin": generate_password_hash("test"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def regen_JSON():
|
def regen_JSON():
|
||||||
|
@ -68,12 +64,28 @@ def update_links():
|
||||||
data = regen_JSON()
|
data = regen_JSON()
|
||||||
outfile = open('data.json', 'w')
|
outfile = open('data.json', 'w')
|
||||||
print(data, file=outfile)
|
print(data, file=outfile)
|
||||||
f.close()
|
outfile.close()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
cur.execute("rollback")
|
cur.execute("rollback")
|
||||||
return "done updating links"
|
return "done updating links"
|
||||||
|
|
||||||
|
@app.route('/editor/links', methods = ['GET'])
|
||||||
|
@auth.login_required
|
||||||
|
def get_links():
|
||||||
|
# endpoint lists all URLs and clicks, returns json object for editor.
|
||||||
|
con = sqlite3.connect(DB_PATH)
|
||||||
|
cur = con.cursor()
|
||||||
|
cur.execute('SELECT position, name, url, clicks FROM links ORDER BY position')
|
||||||
|
|
||||||
|
links_list = []
|
||||||
|
for row in cur.fetchall():
|
||||||
|
d = dict(zip(["position", "name", "url", "clicks"], [row[0], row[1], row[2], row[3]]))
|
||||||
|
links_list.append(d)
|
||||||
|
|
||||||
|
con.close()
|
||||||
|
return jsonify(links_list)
|
||||||
|
|
||||||
@app.route('/clicks', methods=['POST'])
|
@app.route('/clicks', methods=['POST'])
|
||||||
def update_clicks():
|
def update_clicks():
|
||||||
if ('url' not in request.json or 'name' not in request.json):
|
if ('url' not in request.json or 'name' not in request.json):
|
||||||
|
|
Loading…
Reference in New Issue