spiderweb/webapp.py

39 lines
1.2 KiB
Python
Raw Normal View History

2020-01-22 15:18:38 +00:00
import flask
from flask import request, render_template
import MySQLdb as my
import json
app = flask.Flask(__name__)
app.config["DEBUG"] = True
2020-01-22 16:24:20 +00:00
with open('config.json') as json_data_file:
cfg = json.load(json_data_file)
2020-01-22 15:18:38 +00:00
# A route to return all of the available entries in our catalog.
@app.route('/', methods=['GET'])
def spots():
2020-01-22 16:24:20 +00:00
db = my.connect(host=cfg['mysql']['host'],
user=cfg['mysql']['user'],
passwd=cfg['mysql']['passwd'],
db=cfg['mysql']['db']
2020-01-22 15:18:38 +00:00
)
cursor = db.cursor()
number_of_rows = cursor.execute('''SET NAMES 'utf8';''')
number_of_rows = cursor.execute('''SELECT rowid, spotter, freq, spotcall, comment, time from dxcluster.spot ORDER BY rowid desc limit 100;''')
row_headers=[x[0] for x in cursor.description] #this will extract row headers
rv=cursor.fetchall()
payload=[]
for result in rv:
payload.append(dict(zip(row_headers,result)))
db.close()
#print payload
return render_template(
'results.html',
# response=json.dumps(payload)
payload=payload
)
app.run(host='0.0.0.0',port=8080)