mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-14 19:20:05 +00:00
[rankendpoint] Get DB path and endpoint route from env vars
Also reverted the use of main() that made it incompatible with uwsgi and flask run.
This commit is contained in:
parent
f62f3af483
commit
1a3a530c7f
@ -3,18 +3,24 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
header = "SUCCESS"
|
header = "SUCCESS"
|
||||||
|
|
||||||
def main(db_path):
|
db_path = os.environ.get('RANKENDPOINT_DBPATH')
|
||||||
# Opens database in read-only mode
|
route = os.environ.get('RANKENDPOINT_ROUTE')
|
||||||
# Checking same thread disabled for now, which is fine since we never modify anything
|
|
||||||
try:
|
if None in (db_path, route):
|
||||||
db = sqlite3.connect('file:{}?mode=ro'.format(db_path), uri=True, check_same_thread=False)
|
sys.exit('must set RANKENDPOINT_DBPATH and RANKENDPOINT_ROUTE environment variables')
|
||||||
cur = db.cursor()
|
|
||||||
except Exception as ex:
|
# Opens database in read-only mode
|
||||||
print(ex)
|
# Checking same thread disabled for now, which is fine since we never modify anything
|
||||||
sys.exit()
|
try:
|
||||||
|
db = sqlite3.connect('file:{}?mode=ro'.format(db_path), uri=True, check_same_thread=False)
|
||||||
|
cur = db.cursor()
|
||||||
|
except Exception as ex:
|
||||||
|
print(ex)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
#db.set_trace_callback(print)
|
#db.set_trace_callback(print)
|
||||||
|
|
||||||
@ -85,7 +91,7 @@ def get_score_entries(data, name):
|
|||||||
|
|
||||||
return scores
|
return scores
|
||||||
|
|
||||||
@app.route('/getranks', methods=['POST'])
|
@app.route(f'{route}', methods=['POST'])
|
||||||
def rankings():
|
def rankings():
|
||||||
#print("PCUID:", request.form['PCUID'])
|
#print("PCUID:", request.form['PCUID'])
|
||||||
#print("EP_ID:", request.form['EP_ID'])
|
#print("EP_ID:", request.form['EP_ID'])
|
||||||
@ -128,9 +134,3 @@ def rankings():
|
|||||||
# and send it off!
|
# and send it off!
|
||||||
return header + xmlbody
|
return header + xmlbody
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print("Usage: {} <db file>".format(sys.argv[0]))
|
|
||||||
else:
|
|
||||||
main(sys.argv[1])
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user