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
|
@ -55,4 +55,7 @@ You can add a Basic-Auth to the Webgui by setting 3 enviroment Varieables
|
||||||
| FUNK_PASS | HTTP Basic Auth Password |
|
| FUNK_PASS | HTTP Basic Auth Password |
|
||||||
| 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.
|
53
server.py
53
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():
|
||||||
function_updateAccountsAtFunk()
|
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():
|
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,18 +209,19 @@ 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 account["currentPlan"] == nextPlan:
|
if app.debug == False:
|
||||||
print("Plan match, nothing to do")
|
if account["currentPlan"] == nextPlan:
|
||||||
else:
|
print("Plan match, nothing to do")
|
||||||
api = FunkAPI(account["mail"], account["password"])
|
|
||||||
if nextPlan == "1 GB":
|
|
||||||
api.order1GBPlan()
|
|
||||||
elif nextPlan == "unlimited":
|
|
||||||
api.orderUnlimitedPlan()
|
|
||||||
elif nextPlan == "Break":
|
|
||||||
api.startPause()
|
|
||||||
else:
|
else:
|
||||||
print("SOMETHING GO WRONG")
|
api = FunkAPI(account["mail"], account["password"])
|
||||||
|
if nextPlan == "1 GB":
|
||||||
|
api.order1GBPlan()
|
||||||
|
elif nextPlan == "unlimited":
|
||||||
|
api.orderUnlimitedPlan()
|
||||||
|
elif nextPlan == "Break":
|
||||||
|
api.startPause()
|
||||||
|
else:
|
||||||
|
print("SOMETHING GO WRONG")
|
||||||
|
|
||||||
cur.execute("INSERT INTO run_actions VALUES (%s, %s, %s) " % (today.year, today.month, today.day))
|
cur.execute("INSERT INTO run_actions VALUES (%s, %s, %s) " % (today.year, today.month, today.day))
|
||||||
get_db().commit()
|
get_db().commit()
|
||||||
|
@ -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