def query_api_usage_statistics(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) start_utc_time = request.args.get('start_utc_time') end_utc_time = request.args.get('end_utc_time') result = validate_time(start_utc_time, end_utc_time) if result['status'] == 'fail': return jsonify(result) records = calculate_delta(request.cursor, uid, start_utc_time, end_utc_time) clock_time_filter(records) return jsonify(records)
def handle_notify_time(message): user = message.chat.id time = utils.validate_time(message.text) if not time: bot.send_message( chat_id=user, text="Хибний формат часу, спробуйте знову:", reply_markup=get_cancel_button(), ) else: Student.set_notify_time(user, time) bot.delete_message( chat_id=user, message_id=utils.redis_storage.get(f"{user}::time_id")) bot.send_message( chat_id=user, text= f"Тепер Ви будете отримувати сповіщення о <b>{time.time()}</b>.", parse_mode="html", ) utils.redis_storage.delete(user)
def query_ota_special_api_usage(): """ Time format "%Y-%m-%d" """ uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) start_utc_time = request.args.get('start_utc_time') end_utc_time = request.args.get('end_utc_time') cache_key_format = "{rest_api_id}:{user_id}:{date_id}:ota" result = validate_time(start_utc_time, end_utc_time, time_format=DATE_TIME_DAY_FORMAT, validate_func=validate_datetime_format) if result['status'] == 'fail': return jsonify(result) records = query_api_usage(uid, start_utc_time, end_utc_time, time_format=DATE_TIME_DAY_FORMAT, cache_key=cache_key_format) clock_time_filter(records) return jsonify(records)
def admin_upload_results(): try: check = check_admin(session["email"]) except: return redirect(url_for("admin.admin_login")) if check == True: try: profile_pic = session["profile_pic"] facebook_name = session["facebook_name"] all_data = [] fields = [] admins = db.admin correct_data = False wrong_data = True error = "" notify = "" if request.method == "POST": file = request.files["file"] all_data = [] if file: file_name = secure_filename(file.filename) filetype = file_name.split(".")[1] if filetype == "csv": file.save( os.path.join(app.config['UPLOAD_CSV_TEMP'], file_name)) path_to_csv = os.path.join( app.config['UPLOAD_CSV_TEMP'], file_name) open_csv = open(path_to_csv, "rt") try: reader = csv.reader(open_csv) ct = 0 fields = [] for row in reader: dic = {} if ct == 0: fields = row[:] for i in range(len(fields)): fields[i] = fields[i].lower() else: counter = 0 for each in row: dic[fields[counter]] = each counter += 1 dic["valid"] = True ct += 1 if dic != {}: all_data.append(dic) except: pass finally: open_csv.close() ct = 0 flag = 0 for cur_data in all_data: for field in cur_data: if "name" in field: check_name = validate_name(cur_data[field]) if check_name == False: flag = 1 all_data[ct]["valid"] = False if "day" in field: if cur_data[field] != "DNF" and cur_data[ field] != "dnf" and cur_data[ field] != "Dnf": check_time = validate_time( cur_data[field]) if check_time == False: flag = 1 all_data[ct]["valid"] = False ct += 1 if flag == 0: correct_data = True return redirect( url_for("admin.admin_upload_csv", race_name=file_name)) else: error = "Invalid Data in CSV. Change and upload again." wrong_data = False else: error = "Upload file in CSV format only" return render_template("admin_upload_results.html", profile_pic=session["profile_pic"], facebook_name=session["facebook_name"], email=session["email"], all_data=all_data, fields=fields, correct_data=correct_data, wrong_data=wrong_data, error=error, notify=notify) except: session.pop("email", None) session.pop("facebook_name", None) session.pop("profile_pic", None) session.pop("facebook_token", None) return redirect(url_for("admin.admin_login")) else: session.pop("email", None) session.pop("facebook_name", None) session.pop("profile_pic", None) session.pop("facebook_token", None) return redirect(url_for("admin.admin_login"))