Debug Info at Webpage and Cron Time config
This commit is contained in:
parent
1c21ea9389
commit
d8801fd30e
4 changed files with 42 additions and 23 deletions
|
@ -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 |
|
| 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```
|
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.
|
29
server.py
29
server.py
|
@ -18,6 +18,7 @@ DATABASE = os.getenv("FUNK_DATABASE", 'database.db')
|
||||||
USERNAME = os.getenv("FUNK_USER", 'admin')
|
USERNAME = os.getenv("FUNK_USER", 'admin')
|
||||||
PASSWORD = os.getenv("FUNK_PASS", 'geheim')
|
PASSWORD = os.getenv("FUNK_PASS", 'geheim')
|
||||||
ENABLED_AUTH = os.getenv("FUNK_AUTH", False)
|
ENABLED_AUTH = os.getenv("FUNK_AUTH", False)
|
||||||
|
UPDATE_INTERVAL = int(os.getenv("FUNK_UPDATE_INTERVAL", 60*10))
|
||||||
|
|
||||||
|
|
||||||
plans = []
|
plans = []
|
||||||
|
@ -62,7 +63,11 @@ def requires_auth(f):
|
||||||
def function_cron():
|
def function_cron():
|
||||||
print("Run Cron")
|
print("Run Cron")
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
print("Debug Mode:" + str(int(app.debug)))
|
||||||
|
if app.debug == False:
|
||||||
function_updateAccountsAtFunk()
|
function_updateAccountsAtFunk()
|
||||||
|
else:
|
||||||
|
print("Cron don't run in debug mode")
|
||||||
def function_updateAllAccounts():
|
def function_updateAllAccounts():
|
||||||
accounts = function_getAccounts()
|
accounts = function_getAccounts()
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
|
@ -187,8 +192,6 @@ def function_updateAccountsAtFunk():
|
||||||
else:
|
else:
|
||||||
print("Cant update plan!!! ERROR")
|
print("Cant update plan!!! ERROR")
|
||||||
|
|
||||||
function_cron()
|
|
||||||
|
|
||||||
@app.route("/updateAll")
|
@app.route("/updateAll")
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def function_updateAccountsAtFunkOLD():
|
def function_updateAccountsAtFunkOLD():
|
||||||
|
@ -206,6 +209,7 @@ def function_updateAccountsAtFunkOLD():
|
||||||
account = function_getAccount(number[0], True)
|
account = function_getAccount(number[0], True)
|
||||||
print(account)
|
print(account)
|
||||||
nextPlan = function_getPlanForDay(number[0], tomorrow.year, tomorrow.month, tomorrow.day)
|
nextPlan = function_getPlanForDay(number[0], tomorrow.year, tomorrow.month, tomorrow.day)
|
||||||
|
if app.debug == False:
|
||||||
if account["currentPlan"] == nextPlan:
|
if account["currentPlan"] == nextPlan:
|
||||||
print("Plan match, nothing to do")
|
print("Plan match, nothing to do")
|
||||||
else:
|
else:
|
||||||
|
@ -253,7 +257,7 @@ def setupDB():
|
||||||
@app.route("/accounts")
|
@app.route("/accounts")
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def gui_liste():
|
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>")
|
@app.route("/account/<number>")
|
||||||
@requires_auth
|
@requires_auth
|
||||||
|
@ -261,7 +265,7 @@ def gui_account(number):
|
||||||
account = function_getAccount(number)
|
account = function_getAccount(number)
|
||||||
special_days = function_speacialDays(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'])
|
@app.route("/account/<number>/special", methods=['POST'])
|
||||||
@requires_auth
|
@requires_auth
|
||||||
|
@ -300,7 +304,7 @@ def list_days(number):
|
||||||
dayList.append(day)
|
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'])
|
@app.route("/account/add", methods=['GET'])
|
||||||
@requires_auth
|
@requires_auth
|
||||||
|
@ -399,10 +403,17 @@ def print_date_time():
|
||||||
print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
|
print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
|
||||||
|
|
||||||
|
|
||||||
scheduler = BackgroundScheduler()
|
if app.debug == False:
|
||||||
scheduler.add_job(func=function_cron, trigger="interval", seconds=(60*10))
|
print("Start cron");
|
||||||
scheduler.start()
|
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__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=False,host='0.0.0.0')
|
app.run(debug=True,host='0.0.0.0')
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Data Usage</th>
|
<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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<a href="#" class="btn btn-warning btn-sm updateNow">Update now</a>
|
<a href="#" class="btn btn-warning btn-sm updateNow">Update now</a>
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
</nav>
|
</nav>
|
||||||
<div class="row" style="margin-top:20px;">
|
<div class="row" style="margin-top:20px;">
|
||||||
<div class="col-md-12">
|
<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 %}
|
{% block content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue