def douban_items(): # 分虚构类和非虚构类通过`subcat` query string判断 默认虚构类 data = redis_store.lrange('douban_book_fiction:data', 0, -1) timestamp = redis_store.get('douban_book_fiction:timestamp') if request.args.get('subcat', None) == 'I': data = redis_store.lrange('douban_book_non_fiction:data', 0, -1) timestamp = redis_store.get('douban_book_non_fiction:timestamp') return jsonify({ 'update_timestamp': timestamp.decode('utf-8'), 'data': [json.loads(d.decode('utf-8')) for d in data] })
def segmentfault_items(): data = redis_store.lrange('segmentfault:data', 0, -1) timestamp = redis_store.get('segmentfault:timestamp') return jsonify({ 'update_timestamp': timestamp.decode('utf-8'), 'data': [json.loads(d.decode('utf-8')) for d in data] })
def confirm_role_details(): redis_store.set('roles_seen', 0) if request.method == 'POST': redis_store.hmset('contact', request.form.to_dict()) data = { 'role': { 'caption': 'Role details', 'row_data': redis_store.hgetall('role') }, 'logistics': { 'caption': 'Logistical details', 'row_data': redis_store.hgetall('logistics') }, 'security': { 'caption': 'Security details', 'row_data': redis_store.hgetall('security') } } skills = redis_store.lrange('skills', 0, -1) for s in skills: skill_data = { 'row_data': json.loads(redis_store.get(s)), 'caption': s } data[s] = skill_data return render_template('submit/confirm-role-details.html', data=data)
def guard(domain='dev.qrpay.ai', start_url='https://dev.qrpay.ai'): """docstring for main""" lg = LinkGuard(domain, start_url) lg.guard() print('brokens are ') print(redis_store.lrange('broken_links_%s' % (domain), 0, -1)) return True
def daily_guard(): """check for all registered domain every day""" # TODO for effiective write a batch guard rather than use the single guard links = Link.query.all() for link in links: lg = LinkGuard(link.domain, link.base_url) lg.guard() print('brokens are ') print(redis_store.lrange('broken_links_%s' % (link['domain']), 0, -1)) return True
def dump_links2db(self, res): res_dumped = json.dumps(res, default=json_util.default) result = Result(domain=self.domain, result=res_dumped) db.session.add(result) db.session.commit() raw_broken_links = redis_store.lrange('broken_links_%s' % (self.real_domain), 0, -1) broken_links = [link.decode() for link in raw_broken_links] link = Link.query.filter_by(domain=self.domain).first() link.broken_links = broken_links link.last_check_result_id = result.id if broken_links: link.status = 'Failed' else: link.status = 'OK' db.session.add(link) db.session.commit()
def danmaku(): import json if request.method == 'GET': id = request.args.get('id') key = 'movie' + str(id) if redis_store.llen(key): msgs = redis_store.lrange(key, 0, 999) print(msgs) res = { 'code': 1, "danmaku": [json.loads(v) for v in msgs] } else: res = { 'code': 1, "danmaku": [] } resp = json.dumps(res) if request.method == 'POST': data = json.loads(request.get_data()) print(data) msg = { "id": data['id'], "author": data['author'], "time": data['time'], "text": data['text'], "color": data['color'], "type": data['type'], "ip": request.remote_addr, "mid": datetime.datetime.now().strftime('%Y%m%d%H%M%S') + uuid.uuid4().hex, # 'player': [ # data['player'], # ] } # data.append("'ip':request.remote_addr","'_id':datetime.datetime.now().strftime('%Y%m%d%H%M%S') + uuid.uuid4().hex") res = { 'code': 1, 'data': msg } resp = json.dumps(res) redis_store.lpush('movie' + str(msg['mid']), json.dumps(msg)) return Response(resp, mimetype='application/json')
def get_pundit_data(self, obj): if str(obj.id) in redis_store.lrange(str(obj.pundit_id), 0, -1): redis_store.lrem(str(obj.pundit_id), str(obj.id)) return True else: return False
def move(): """转移""" req_dict = request.get_json() lingpai = req_dict.get('lingpai', '') subject = req_dict.get('subject', '') # 主题 item = req_dict.get('item', '') # 事项 water_num = req_dict.get('water_num', '') user_id = req_dict.get("user_id", '') addr = req_dict.get("work_addr", '') print("转移-------", req_dict) # 校验数据 param_keys = [ "lingpai", "subject", "item", "water_num", "user_id", 'work_addr' ] param_dict = dict() for i in param_keys: param_dict.__setitem__(i, req_dict.get(i, '')) for key, value in param_dict.items(): if not value: return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key) # 修改当前叫号情况 current_call_obj = CurrentCall.query.filter_by(water_num=water_num).first() if current_call_obj: current_call_obj.status = 1 db.session.add(current_call_obj) db.session.commit() # 修改用户当前状态 lingpai_obj = LingPai.query.filter_by(user_id=user_id).first() if not lingpai_obj: return jsonify(errno=RET.DBERR, errmsg="未登录") lingpai_obj.status = "空闲" db.session.add(lingpai_obj) db.session.commit() # 修改数据 try: business = Business.query.filter_by(water_num=water_num).first() old_subject = business.subject business.subject = subject business.item = item business.move_times += 1 db.session.add(business) db.session.commit() except Exception as e: current_app.logger.error(e) db.session.rollback() return jsonify(errno=RET.DBERR, errmsg="数据库操作错误") # 根据排队时间将数据放入相应队列 try: time_list = redis_store.lrange(addr + subject + "time", 0, -1) if time_list: for j in range(len(time_list)): if business.create_time.strftime( '%H%M%S').encode() < time_list[j]: redis_store.linsert(addr + subject, 'before', redis_store.lindex(addr + subject, j), water_num) redis_store.linsert( addr + subject + "time", 'before', redis_store.lindex(addr + subject + "time", j), business.create_time.strftime('%H%M%S')) else: print("enter else branch") redis_store.rpush(addr + subject, water_num) redis_store.rpush(addr + subject + "time", business.create_time.strftime('%H%M%S')) else: print("enter no branch") redis_store.lpush(addr + subject, water_num) redis_store.lpush(addr + subject + "time", business.create_time.strftime('%H%M%S')) # 修改用户头顶屏幕显示 redis_store.rpush( 'usershead', json.dumps({ "lingpai": lingpai, "length": redis_store.llen(addr + old_subject), "show": "false" })) # 修改用户对面屏幕显示 redis_store.rpush('itemreviews', json.dumps({ "lingpai": lingpai, "show": "false" })) except Exception as e: current_app.logger.error(e) return jsonify(errno=RET.SERVERERR, errmsg="内部错误") return jsonify(errno=RET.OK, errmsg="成功")