diff --git a/Readme.md b/Readme.md index d3da8cd..0c29e57 100644 --- a/Readme.md +++ b/Readme.md @@ -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_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``` \ No newline at end of file +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. \ No newline at end of file diff --git a/server.py b/server.py index 16c4fe6..5e36a16 100644 --- a/server.py +++ b/server.py @@ -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(): - 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(): 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,18 +209,19 @@ def function_updateAccountsAtFunkOLD(): account = function_getAccount(number[0], True) print(account) nextPlan = function_getPlanForDay(number[0], tomorrow.year, tomorrow.month, tomorrow.day) - if account["currentPlan"] == nextPlan: - print("Plan match, nothing to do") - else: - api = FunkAPI(account["mail"], account["password"]) - if nextPlan == "1 GB": - api.order1GBPlan() - elif nextPlan == "unlimited": - api.orderUnlimitedPlan() - elif nextPlan == "Break": - api.startPause() + if app.debug == False: + if account["currentPlan"] == nextPlan: + print("Plan match, nothing to do") 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)) get_db().commit() @@ -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/") @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//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') \ No newline at end of file + app.run(debug=True,host='0.0.0.0') + + \ No newline at end of file diff --git a/templates/account.html b/templates/account.html index 84b6288..68db203 100644 --- a/templates/account.html +++ b/templates/account.html @@ -31,7 +31,7 @@ Data Usage - {{ account["dataUsed"]|round(2) }}% + {{ account["dataUsed"]|round(2) }}% See Statistics Update now diff --git a/templates/base.html b/templates/base.html index 23ae413..69191d6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,6 +28,11 @@
+ {% if debug %} + + {% endif %} {% block content %}{% endblock %}