mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-22 22:10:05 +00:00
Compare commits
No commits in common. "9deba1956f62f5a2818d214ad8d62533ad793a0b" and "f62f3af483c49652a3ed5bb8885164ca9a588957" have entirely different histories.
9deba1956f
...
f62f3af483
@ -1,27 +1,12 @@
|
|||||||
# This script serves an HTTP endpoint that provides the racing scores.
|
|
||||||
#
|
|
||||||
# Example invocation for testing:
|
|
||||||
# $ RANKENDPOINT_DBPATH=/path/to/database.db RANKENDPOINT_ROUTE=/getranks flask --app rankendpoint.py run
|
|
||||||
#
|
|
||||||
# Example invocation in production (behind a properly configured gateway like nginx):
|
|
||||||
# $ RANKENDPOINT_DBPATH=/path/to/database.db RANKENDPOINT_ROUTE=/getranks uwsgi \
|
|
||||||
# -s localhost:3031 --manage-script-name --mount /=rankendpoint:app --plugin python3
|
|
||||||
|
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
|
|
||||||
header = "SUCCESS"
|
header = "SUCCESS"
|
||||||
|
|
||||||
db_path = os.environ.get('RANKENDPOINT_DBPATH')
|
def main(db_path):
|
||||||
route = os.environ.get('RANKENDPOINT_ROUTE')
|
|
||||||
|
|
||||||
if None in (db_path, route):
|
|
||||||
sys.exit('must set RANKENDPOINT_DBPATH and RANKENDPOINT_ROUTE environment variables')
|
|
||||||
|
|
||||||
# Opens database in read-only mode
|
# Opens database in read-only mode
|
||||||
# Checking same thread disabled for now, which is fine since we never modify anything
|
# Checking same thread disabled for now, which is fine since we never modify anything
|
||||||
try:
|
try:
|
||||||
@ -100,8 +85,7 @@ def get_score_entries(data, name):
|
|||||||
|
|
||||||
return scores
|
return scores
|
||||||
|
|
||||||
# route should be something like /getranks
|
@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'])
|
||||||
@ -144,3 +128,9 @@ 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