add functions.py and prediction checks
This commit is contained in:
parent
ff088a6a24
commit
ba69c2a97f
16
freeriders/functions.py
Normal file
16
freeriders/functions.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
def formatprefix2(number):
|
||||||
|
return "{:02d}".format(number)
|
||||||
|
|
||||||
|
def formatprefix10(number):
|
||||||
|
return "{:010d}".format(number)
|
||||||
|
|
||||||
|
def predict(timestamp):
|
||||||
|
base_ticket = 4339636
|
||||||
|
base_timestamp = 1694003498
|
||||||
|
step = 8
|
||||||
|
|
||||||
|
ticket = base_ticket + (int(time.time()) - base_timestamp) * step
|
||||||
|
return ticket
|
||||||
|
|
@ -1,18 +1,27 @@
|
|||||||
from flask import render_template, request, redirect
|
from flask import render_template, request, redirect
|
||||||
from freeriders import app, db
|
from freeriders import app, db
|
||||||
|
from freeriders.functions import formatprefix2,formatprefix10, predict
|
||||||
from freeriders.models import Tickets
|
from freeriders.models import Tickets
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
PREDICTTIMERANGE = 60 * 80
|
||||||
|
|
||||||
@app.route('/sms', methods=['GET'])
|
@app.route('/sms', methods=['GET'])
|
||||||
def sms():
|
def sms():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
timenow = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lastticket = Tickets.query.order_by(Tickets.timestamp.desc()).first().ticket
|
lastticket = Tickets.query.order_by(Tickets.timestamp.desc()).first()
|
||||||
lastticket = "{:010d}".format(lastticket)
|
|
||||||
|
if lastticket.timestamp < timenow - (90 * 60):
|
||||||
|
lastticket = formatprefix10(predict(timenow))
|
||||||
|
else:
|
||||||
|
lastticket = formatprefix10(lastticket.ticket)
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
datenow = f'{"{:02d}".format(date.day)}.{"{:02d}".format(date.month)}.{date.year}'
|
datenow = f'{formatprefix2(date.day)}.{formatprefix2(date.month)}.{date.year}'
|
||||||
timenow = f'{"{:02d}".format(date.hour)}:{"{:02d}".format(date.minute)}:{date.second}'
|
timenow = f'{formatprefix2(date.hour)}:{formatprefix2(date.minute)}:formatprefix2{date.second}'
|
||||||
return render_template('sms.html', ticket = lastticket, date = datenow, time = timenow)
|
return render_template('sms.html', ticket = lastticket, date = datenow, time = timenow)
|
||||||
except:
|
except:
|
||||||
return 'Error retriving last ticket'
|
return 'Error retriving last ticket'
|
||||||
@ -27,8 +36,11 @@ def submit():
|
|||||||
timenow = int(time.time())
|
timenow = int(time.time())
|
||||||
ticket_input = request.form['ticket']
|
ticket_input = request.form['ticket']
|
||||||
|
|
||||||
if ticket_input.isdigit() and len(ticket_input) == 10:
|
if ticket_input.isdigit() and len(ticket_input) == 10 :
|
||||||
ticket = Tickets(ticket = int(ticket_input), timestamp = timenow)
|
if ticket_input < predict(timenow + PREDICTTIMERANGE ) and ticket_input > predict(timenow - PREDICTTIMERANGE ) :
|
||||||
|
ticket = Tickets(ticket = int(ticket_input), timestamp = timenow)
|
||||||
|
else:
|
||||||
|
return 'Ticket number is in unexpected range.'
|
||||||
else:
|
else:
|
||||||
return 'Ticket format is wrong. Only 10 digits allowed.'
|
return 'Ticket format is wrong. Only 10 digits allowed.'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user