def home(): latest_values = json.loads( cache.get('values').decode()) if cache.get('values') else [] return render_template('index.html', values=latest_values, refreshInterval=app.config.get( 'REFRESH_INTERVAL', 250))
def main(): mask_count = cache.get('mask_count').decode() if cache.get('mask_count') else 0 nomask_count = cache.get('nomask_count').decode() if cache.get('nomask_count') else 0 timestamp = convert_unixepoch_to_time(time.time()) return render_template('index.html', mask_count=mask_count, nomask_count=nomask_count, timestamp=timestamp, barcodes=[], refreshInterval=Config.REFRESH_INTERVAL, camera_name=Config.LOCATION, version=Config.VERSION)
def account_decline(): page = request.args.get('page') limit = request.args.get('limit') alias_name = request.args.get("acc_name") ca_data = cache.get('finance_decline_data') if not ca_data: data = SqlDataNative.bento_alltrans() acc_sum_trans = dict() for i in data: cus = i.get('before_balance') if cus not in acc_sum_trans: cus_dict = dict() cus_dict[cus] = {'decl': 0, 't_data': 0, 'three_decl': 0, 'three_tran': 0} acc_sum_trans.update(cus_dict) for n in data: date = n.get('date') do_type = n.get('do_type') cus = n.get('before_balance') value = {'t_data': acc_sum_trans.get(cus).get('t_data') + 1} acc_sum_trans.get(cus).update(value) if do_type == 'DECLINED': value = {'decl': acc_sum_trans.get(cus).get('decl') + 1} acc_sum_trans.get(cus).update(value) today_time = time.strftime('%Y-%m-%d', time.localtime(time.time())) max_today = datetime.datetime.strptime("{} {}".format(change_today(today_time, 0), "23:59:59"), '%Y-%m-%d %H:%M:%S') min_today = datetime.datetime.strptime("{} {}".format(change_today(today_time, -3), "23:59:59"), '%Y-%m-%d %H:%M:%S') trans_t = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S') if min_today <= trans_t <= max_today: value = {'three_tran': acc_sum_trans.get(cus).get('three_tran') + 1} acc_sum_trans.get(cus).update(value) if min_today < trans_t < max_today and do_type == 'DECLINED': value = {'three_decl': acc_sum_trans.get(cus).get('three_decl') + 1} acc_sum_trans.get(cus).update(value) res = list() for n in acc_sum_trans: value = acc_sum_trans.get(n) value['alias'] = n value['all_bili'] = "{} {}".format(float("%.4f" % (value.get('decl') / value.get('t_data') * 100)), "%") if value.get('decl') != 0 else 0 value['bili'] = "{} {}".format(float("%.4f" % (value.get('three_decl') / value.get('three_tran') * 100)), "%") if value.get('three_tran') != 0 else 0 if value.get('three_tran') != 0 and value.get('three_decl') / value.get('three_tran') > 0.1: value['show'] = 'T' else: value['show'] = 'F' res.append(value) # 设置缓存 cache.set('finance_decline_data', res, timeout=60 * 60 * 6) else: res = ca_data if alias_name: res_alias = list() for i in res: if alias_name in i.get('alias'): res_alias.append(i) return jsonify({"code": 0, "count": len(res_alias), "data": res_alias, "msg": "SUCCESSFUL"}) return jsonify({"code": 0, "count": len(res), "data": res, "msg": "SUCCESSFUL"})
def get_materiascursadas(self, token, carrera): cache_data = cache.get(carrera) if cache_data: result = json.loads(cache_data) else: data = self.retrieve_materiascursadas(token, carrera) cache.set(carrera, json.dumps(data, ensure_ascii=False).encode('utf8')) result = data return result
def get(self): cached = cache.get('user_%s' % self.user_id) if cached: logger.info('Sent from cache user_%s' % self.user_id) return cached else: q = db.query(User).filter(User.user_id == self.user_id).all()[0] cache.set('user_%s' % self.user_id, q) logger.info('Added to cache user_%s' % self.user_id) return q
def get(self): cached = cache.get('room_%s' % self.id) if cached: logger.info('Sent from cache room_%s' % self.id) return cached[0] else: q = db.query(Room).filter(Room.id == self.id).all() cache.set('room_%s' % self.id, q) logger.info('Added to cache room_%s' % self.id) return q[0]
def getTakenSubjects(self, token, subjectCode): cache_data = cache.get(subjectCode) if cache_data: result = json.loads(cache_data) else: data = self.retrieveTakenSubjects(token, subjectCode) cache.set(subjectCode, json.dumps(data, ensure_ascii=False).encode('utf8')) result = data return result
def get(self, model=None): cached = cache.get('item_%s' % self.id) res = None if cached: logger.info('Sent from cache item_%s' % self.id) res = '{0} ({1})'.format(cached[0].title, cached[0].value) if model: res = cached[0] else: q = db.query(Item).filter(Item.id == self.id).all() if q: cache.set('item_%s' % self.id, q) logger.info('Added to cache item_%s' % self.id) res = '{0} ({1})'.format(q[0].title, q[0].value) if model: res = q[0] else: res = 'Нет' return res
def all_trans(): page = request.args.get("page") limit = request.args.get("limit") # 客户名 acc_name = request.args.get("acc_name") # 卡的名字 order_num = request.args.get("order_num") # 时间范围 time_range = request.args.get("time_range") # 操作状态 trans_status = request.args.get("trans_status") # 交易类型 trans_store = request.args.get("trans_store") args_list = [] ca_data = cache.get('all_trans') # 设置缓存处理查询到的大量数据(6小时) if ca_data: data = ca_data else: data = SqlDataNative.bento_alltrans() cache.set('all_trans', data, timeout=60 * 60 * 6) results = {"code": RET.OK, "msg": MSG.OK, "count": 0, "data": ""} if len(data) == 0: results["MSG"] = MSG.NODATA return jsonify(results) # 下列判断为判断是否有搜索条件根据条件过滤 acc_list = list() if acc_name: # args_list.append(acc_name) for i in data: cus = i.get('before_balance') if acc_name == cus: acc_list.append(i) else: acc_list = data order_list = list() if order_num: # args_list.append(order_num) for c in acc_list: card_name = c.get('hand_money') if order_num in card_name: order_list.append(c) else: order_list = acc_list trans_list = list() if trans_status: args_list.append(trans_status) for i in order_list: do_type = i.get('card_num') if trans_status in do_type: trans_list.append(i) else: trans_list = order_list time_list = list() if time_range: min_time = time_range.split(' - ')[0] + ' 00:00:00' max_time = time_range.split(' - ')[1] + ' 23:59:59' min_tuple = datetime.datetime.strptime(min_time, '%Y-%m-%d %H:%M:%S') max_tuple = datetime.datetime.strptime(max_time, '%Y-%m-%d %H:%M:%S') for d in trans_list: dat = datetime.datetime.strptime(d.get("date"), '%Y-%m-%d %H:%M:%S') if min_tuple < dat < max_tuple: time_list.append(d) else: time_list = trans_list store_list = list() if trans_store: for i in time_list: trans_type = i.get('trans_type') if trans_store in trans_type: store_list.append(i) else: store_list = trans_list if not store_list: return jsonify({'code': RET.OK, 'msg': MSG.NODATA}) page_list = list() data = sorted(store_list, key=operator.itemgetter("date")) data = list(reversed(data)) for i in range(0, len(data), int(limit)): page_list.append(data[i: i + int(limit)]) results["data"] = page_list[int(page) - 1] results["count"] = len(data) return jsonify(results)
def api(): mask_count = cache.get('mask_count').decode() if cache.get('mask_count') else 0 nomask_count = cache.get('nomask_count').decode() if cache.get('nomask_count') else 0 timestamp = convert_unixepoch_to_time(time.time()) api = {'image_timestamp': timestamp, 'mask_count': mask_count, 'nomask_count': nomask_count} return jsonify(api)
def image_still(): image = cache.get('image') if image: return send_file(io.BytesIO(image), mimetype='image/jpeg') else: return send_file('static/no_feed.jpeg', mimetype='image/jpeg')
def values(): latest_values = json.loads( cache.get('values').decode()) if cache.get('values') else {} return jsonify(latest_values)
def register(): ''' 用户注册界面 :return: ''' if request.method == 'GET': middle_key = request.args.get('middle_key') if middle_key: try: string = Base64Code().base_decrypt(middle_key.strip()) # 验证解密后的参数是否是符合要求(id_用户名_账号) info_list = string.split('_') middle_id = info_list[0] name = SqlData().search_middle_field('name', middle_id) account = SqlData().search_middle_field('account', middle_id) if info_list[1] != name or info_list[2] != account: return "<html><div style='position:absolute;z-index:99;padding-top:346px;left:50%;margin-left:-600px;'>" \ "<h1>{}</h1><div></html>".format('链接残缺请使用正确的介绍链接注册!!') except: return "<html><div style='position:absolute;z-index:99;padding-top:346px;left:50%;margin-left:-600px;'>" \ "<h1>{}</h1><div></html>".format('链接残缺请使用正确的介绍链接注册!') # 给界面设置一个使用cache的key,设置唯一的key核对验证码 ver_key = verify_code(18) context = dict() context['ver_key'] = ver_key context['middle_key'] = middle_key if middle_key else '' return render_template('user/register.html', **context) if request.method == 'POST': try: data = json.loads(request.form.get('data')) u_name = data.get('u_name') u_acc = data.get('u_acc') u_pass = data.get('u_pass') phone = data.get('phone') ver_code = data.get('ver_code') ver_key = data.get('ver_key') # 取出缓存中验证码 server_code = cache.get(ver_key) # server_code = '111' # 以下是对注册参数的校验 if not all([u_name, u_pass, phone, ver_code, ver_key]): return jsonify({'code': RET.SERVERERROR, 'msg': '请补全信息后提交!'}) chinese = is_chinese(u_acc) if chinese: return jsonify({'code': RET.SERVERERROR, 'msg': '账号中包含中文!'}) # 检验用户名和账号是否存在 res1 = SqlData().search_user_field_name('id', u_name) # 每天用户名默认电话,所以没有用户名就检验电话 if not u_acc: u_acc = phone res2 = SqlData().search_user_info(u_acc) if res1 or res2: return jsonify({'code': RET.SERVERERROR, 'msg': '用户名或账号已存在!'}) if not 6 <= len(u_pass) <= 12: return jsonify({'code': RET.SERVERERROR, 'msg': '密码长度不符合要求!'}) if 8 < len(u_name): return jsonify({'code': RET.SERVERERROR, 'msg': '用户名过长!'}) if 18 < len(u_acc): return jsonify({'code': RET.SERVERERROR, 'msg': '账号长度过长!'}) if server_code is None: return jsonify({'code': RET.SERVERERROR, 'msg': '验证码过期!请重新获取!'}) if ver_code != server_code: return jsonify({'code': RET.SERVERERROR, 'msg': '验证码错误请刷新后重试!'}) else: return jsonify({'code': RET.OK, 'msg': MSG.OK}) except Exception as e: logging.error(str(e)) return jsonify({'code': RET.SERVERERROR, 'msg': MSG.SERVERERROR})