diff --git a/server.py b/server.py index 5e36a16..50d3395 100644 --- a/server.py +++ b/server.py @@ -192,50 +192,6 @@ def function_updateAccountsAtFunk(): else: print("Cant update plan!!! ERROR") -@app.route("/updateAll") -@requires_auth -def function_updateAccountsAtFunkOLD(): - cur = get_db().cursor() - today = datetime.datetime.now() - done = cur.execute("SELECT count(*) FROM run_actions WHERE year = %s AND month = %s AND day = %s" % (today.year, today.month, today.day)).fetchone() - - if done[0] == 0: - numbers = cur.execute("SELECT number FROM accounts").fetchall() - tomorrow = datetime.date.today() + datetime.timedelta(days=1) - - for number in numbers: - print("Update Account: "+str(number[0])) - #function_updateAccount(number[0]) - 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: - 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() - - return "OK"; - - - - else: - return "Done for today" - - - - #Routes @app.route("/") @requires_auth @@ -267,6 +223,31 @@ def gui_account(number): return render_template("account.html", debug=app.debug, account=account, plans=plans, special_days=special_days, currentTime=int(time.time())) +@app.route("/account//statistics") +@requires_auth +def gui_statistic(number): + cur = get_db().cursor() + ende = datetime.datetime.now() + start = ende - relativedelta(months=1) + + delta = ende - start + dayList = [] + + for i in range(delta.days + 1): + day = {} + date = start + datetime.timedelta(days=i) + dayStart = datetime.datetime(date.year, date.month, date.day, 0, 0, 0) + dayEnde = datetime.datetime(date.year, date.month, date.day, 23, 59, 59) + day["date"] = str(date.day)+"."+str(date.month)+"."+str(date.year) + lastUpdate = cur.execute("SELECT dataUsed, updateTime FROM `updates` WHERE `number` = %s AND `updateTime` > %s AND `updateTime` < %s ORDER BY `updateTime` DESC" % (number, int(dayStart.timestamp()), int(dayEnde.timestamp()))).fetchone() + if lastUpdate == None: + day["usage"] = 0 + else: + day["usage"] = round(lastUpdate[0], 4); + dayList.append(day) + + return render_template("statistics.html", debug=app.debug, dayList=dayList) + @app.route("/account//special", methods=['POST']) @requires_auth def special_days(number): diff --git a/templates/account.html b/templates/account.html index 68db203..d46084b 100644 --- a/templates/account.html +++ b/templates/account.html @@ -31,7 +31,7 @@ Data Usage - {{ account["dataUsed"]|round(2) }}% See Statistics + {{ account["dataUsed"]|round(2) }}% See Statistics Update now @@ -177,6 +177,7 @@ {% endif %} {% endfor %} +
diff --git a/templates/statistics.html b/templates/statistics.html new file mode 100644 index 0000000..699271e --- /dev/null +++ b/templates/statistics.html @@ -0,0 +1,43 @@ +{% extends "base.html" %} +{% block content %} + +

Statistics

+ + +{% endblock %} \ No newline at end of file