Debug Info at Webpage and Cron Time config

This commit is contained in:
Kekskurse 2019-07-09 11:23:51 +02:00
parent 1c21ea9389
commit d8801fd30e
4 changed files with 42 additions and 23 deletions

View file

@ -56,3 +56,6 @@ You can add a Basic-Auth to the Webgui by setting 3 enviroment Varieables
| FUNK_AUTH | Must be set (e.g. to one) to enabled Basic-Auth |
Also you can change the Path of sqlite Database file with the enviroment variable FUNK_DATABASE e.g. if you want to save it in the tmp folder ```FUNK_DATABASE=/tmp/funk.db```
## Update Interval
In this interval the cron will update the current plan and send changes to FUNK. If you want to change it set the numer in secounds to the env FUNK_UPDATE_INTERVAL.

View file

@ -18,6 +18,7 @@ DATABASE = os.getenv("FUNK_DATABASE", 'database.db')
USERNAME = os.getenv("FUNK_USER", 'admin')
PASSWORD = os.getenv("FUNK_PASS", 'geheim')
ENABLED_AUTH = os.getenv("FUNK_AUTH", False)
UPDATE_INTERVAL = int(os.getenv("FUNK_UPDATE_INTERVAL", 60*10))
plans = []
@ -62,7 +63,11 @@ def requires_auth(f):
def function_cron():
print("Run Cron")
with app.app_context():
print("Debug Mode:" + str(int(app.debug)))
if app.debug == False:
function_updateAccountsAtFunk()
else:
print("Cron don't run in debug mode")
def function_updateAllAccounts():
accounts = function_getAccounts()
for account in accounts:
@ -187,8 +192,6 @@ def function_updateAccountsAtFunk():
else:
print("Cant update plan!!! ERROR")
function_cron()
@app.route("/updateAll")
@requires_auth
def function_updateAccountsAtFunkOLD():
@ -206,6 +209,7 @@ def function_updateAccountsAtFunkOLD():
account = function_getAccount(number[0], True)
print(account)
nextPlan = function_getPlanForDay(number[0], tomorrow.year, tomorrow.month, tomorrow.day)
if app.debug == False:
if account["currentPlan"] == nextPlan:
print("Plan match, nothing to do")
else:
@ -253,7 +257,7 @@ def setupDB():
@app.route("/accounts")
@requires_auth
def gui_liste():
return render_template("list.html", accounts=function_getAccounts(), currentTime=int(time.time()))
return render_template("list.html", debug=app.debug, accounts=function_getAccounts(), currentTime=int(time.time()))
@app.route("/account/<number>")
@requires_auth
@ -261,7 +265,7 @@ def gui_account(number):
account = function_getAccount(number)
special_days = function_speacialDays(number)
return render_template("account.html", account=account, plans=plans, special_days=special_days, currentTime=int(time.time()))
return render_template("account.html", debug=app.debug, account=account, plans=plans, special_days=special_days, currentTime=int(time.time()))
@app.route("/account/<number>/special", methods=['POST'])
@requires_auth
@ -300,7 +304,7 @@ def list_days(number):
dayList.append(day)
return render_template("list_days.html", dayList=dayList)
return render_template("list_days.html", debug=app.debug, dayList=dayList)
@app.route("/account/add", methods=['GET'])
@requires_auth
@ -399,10 +403,17 @@ def print_date_time():
print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
scheduler = BackgroundScheduler()
scheduler.add_job(func=function_cron, trigger="interval", seconds=(60*10))
scheduler.start()
if app.debug == False:
print("Start cron");
scheduler = BackgroundScheduler()
scheduler.add_job(func=function_cron, trigger="interval", seconds=(UPDATE_INTERVAL))
scheduler.start()
else:
print("Dont start crons in Debug Mode!")
if __name__ == '__main__':
app.run(debug=False,host='0.0.0.0')
app.run(debug=True,host='0.0.0.0')

View file

@ -31,7 +31,7 @@
</tr>
<tr>
<th>Data Usage</th>
<td>{{ account["dataUsed"]|round(2) }}%</td>
<td>{{ account["dataUsed"]|round(2) }}% <a href="#" class="btn btn-sm btn-success">See Statistics</a></td>
</tr>
</table>
<a href="#" class="btn btn-warning btn-sm updateNow">Update now</a>

View file

@ -28,6 +28,11 @@
</nav>
<div class="row" style="margin-top:20px;">
<div class="col-md-12">
{% if debug %}
<div class="alert alert-warning" role="alert">
App is in Debug / Developer mode
</div>
{% endif %}
{% block content %}{% endblock %}
</div>
</div>