|
|
@ -1,18 +1,17 @@
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import signal
|
|
|
|
|
|
|
|
|
|
|
|
import gevent
|
|
|
|
import gevent
|
|
|
|
import gevent.backdoor
|
|
|
|
import gevent.backdoor
|
|
|
|
from gevent.pywsgi import WSGIServer
|
|
|
|
from gevent.pywsgi import WSGIServer
|
|
|
|
import flask
|
|
|
|
import flask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import common
|
|
|
|
from common import database
|
|
|
|
from common import database
|
|
|
|
#from stats import stats, after_request
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = flask.Flask('thrimshim')
|
|
|
|
app = flask.Flask('thrimshim')
|
|
|
|
#app.after_request(after_request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cors(app):
|
|
|
|
def cors(app):
|
|
|
|
"""WSGI middleware that sets CORS headers"""
|
|
|
|
"""WSGI middleware that sets CORS headers"""
|
|
|
@ -30,22 +29,19 @@ def cors(app):
|
|
|
|
return app(environ, _start_response)
|
|
|
|
return app(environ, _start_response)
|
|
|
|
return handle
|
|
|
|
return handle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/thrimshim/<uuid:key>', methods=['GET', 'POST'])
|
|
|
|
@app.route('/thrimshim/<uuid:key>', methods=['GET', 'POST'])
|
|
|
|
def thrimshim(key):
|
|
|
|
def thrimshim(key):
|
|
|
|
if flask.request.method == 'POST':
|
|
|
|
if flask.request.method == 'POST':
|
|
|
|
row = flask.request.json
|
|
|
|
row = flask.request.json
|
|
|
|
update_row(row)
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
get_row(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def date_handler(obj):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_row(ident):
|
|
|
|
def get_row(ident):
|
|
|
|
conn = flask.g.db_manager.get_conn()
|
|
|
|
conn = app.db_manager.get_conn()
|
|
|
|
with database.transaction(conn):
|
|
|
|
with database.transaction(conn):
|
|
|
|
result = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident
|
|
|
|
results = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident)
|
|
|
|
row = results[0]
|
|
|
|
row = results[0]
|
|
|
|
assert row.id == ident
|
|
|
|
assert row.id == ident
|
|
|
|
response = row._asdict()
|
|
|
|
response = row._asdict()
|
|
|
@ -53,53 +49,50 @@ def get_row(ident):
|
|
|
|
return json.dump(response)
|
|
|
|
return json.dump(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_row(ident):
|
|
|
|
#def query_database(ident):
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error
|
|
|
|
def query_database(ident):
|
|
|
|
# from database where id is ident
|
|
|
|
|
|
|
|
#
|
|
|
|
select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error
|
|
|
|
#def set_row(data):
|
|
|
|
from database where id is ident
|
|
|
|
# to_update = unjson(data)
|
|
|
|
|
|
|
|
#
|
|
|
|
def set_row(data):
|
|
|
|
# update_database(to_update)
|
|
|
|
to_update = unjson(data)
|
|
|
|
#
|
|
|
|
|
|
|
|
#def update_database(ident, to_update):
|
|
|
|
update_database(to_update)
|
|
|
|
#
|
|
|
|
|
|
|
|
# if state not in ['UNEDITED, EDITED, CLAIMED']:
|
|
|
|
def update_database(ident, to_update):
|
|
|
|
# return 'Video already published'
|
|
|
|
|
|
|
|
#
|
|
|
|
if state not in ['UNEDITED, EDITED, CLAIMED']:
|
|
|
|
# insert video_title, video_description, video_start, video_end
|
|
|
|
return 'Video already published'
|
|
|
|
# #allow_holes, uploader_whitelist, upload_location
|
|
|
|
|
|
|
|
# into database where id == indent
|
|
|
|
insert video_title, video_description, video_start, video_end
|
|
|
|
#
|
|
|
|
#allow_holes, uploader_whitelist, upload_location
|
|
|
|
# set error to NULL
|
|
|
|
into database where id == indent
|
|
|
|
# set uploader to NULL
|
|
|
|
|
|
|
|
#
|
|
|
|
set error to NULL
|
|
|
|
# if upload_location:
|
|
|
|
set uploader to NULL
|
|
|
|
# set state to 'DONE'
|
|
|
|
|
|
|
|
#
|
|
|
|
if upload_location:
|
|
|
|
# if publish:
|
|
|
|
set state to 'DONE'
|
|
|
|
# set state to 'EDITED'
|
|
|
|
|
|
|
|
# else:
|
|
|
|
if publish:
|
|
|
|
# set state to 'UNEDITED'
|
|
|
|
set state to 'EDITED'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
set state to 'UNEDITED'
|
|
|
|
|
|
|
|
|
|
|
|
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flask.g.db_manager = database.DBManager(dsn=connection_string)
|
|
|
|
|
|
|
|
server = WSGIServer((host, port), cors(app))
|
|
|
|
server = WSGIServer((host, port), cors(app))
|
|
|
|
|
|
|
|
app.db_manager = database.DBManager(dsn=connection_string)
|
|
|
|
|
|
|
|
|
|
|
|
def stop():
|
|
|
|
def stop():
|
|
|
|
logging.info("Shutting down")
|
|
|
|
logging.info("Shutting down")
|
|
|
|
server.stop()
|
|
|
|
server.stop()
|
|
|
|
gevent.signal(signal.SIGTERM, stop)
|
|
|
|
gevent.signal(signal.SIGTERM, stop)
|
|
|
|
|
|
|
|
|
|
|
|
PromLogCountsHandler.install()
|
|
|
|
common.PromLogCountsHandler.install()
|
|
|
|
install_stacksampler()
|
|
|
|
common.install_stacksampler()
|
|
|
|
|
|
|
|
|
|
|
|
if backdoor_port:
|
|
|
|
if backdoor_port:
|
|
|
|
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()
|
|
|
|
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()
|
|
|
|