def lists(params): """ 插入用户 """ params['p'] = params['input']['p'] params['l'] = params['input']['l'] offset = (params['p'] - 1) * params['l'] # 查询用户列表 lists = auth_db.query_user_lists(offset, params['input']['l']) return api_response({'c': 0})
def insert(params): """ 插入用户 """ # 查询用户名信息 params['user_info'] = auth_db.query_user_by_name(params['input']['name']) if not params['user_info']: auth_db.insert_user(params['input']) else: auth_db.update_user(params['user_info'], params['input']) return api_response({'c': 0})
def save_image(): """ 保存图片 """ import base64, os prefix = 'data:image/png;base64,' # 读图片数据 filename = os.path.join(CM_STATIC_PATH, 'images/img.png') fp = open(filename, 'rb') data = prefix + base64.b64encode(fp.read()).decode('utf-8') params = { 'input': { 'type': PICTURE_TYPE_PNG, 'file': 'wechat', 'icon': data, } } # 查询路径 path = AWS['s3_buckets']['wxiao'][params['input']['file']]['path'] icon_name = md5(params['input']['icon']) if params['input']['type'] == PICTURE_TYPE_PNG: # 生产文件名 icon_name = '{0}.png'.format(icon_name) elif params['input']['type'] == PICTURE_TYPE_GIF: # 生产文件名 icon_name = '{0}.gif'.format(icon_name) elif params['input']['type'] == PICTURE_TYPE_JPG: # 生产文件名 icon_name = '{0}.jpg'.format(icon_name) # 文件路径名 icon_name = '{0}/{1}'.format(path, icon_name) # 保存图片 icon = base64.b64decode(params['input']['icon'][22:]) # 去掉前面23个字符的标示符 # 临时保存在缓存中 output = BytesIO() output.write(icon) img_data = output.getvalue() output.close() # 上传图片到s3 s3.Bucket(AWS['s3_buckets']['wxiao']['name']).put_object(Key=icon_name, Body=img_data) return api_response({'c': 0})
def user_inform(params): # 测试通知用户信息 message = { 'uid': randint(0, 30000), 'inform': u'Hello Word!', } from app.task.user import user_inform message = user_inform(message) # message = task_celery.send_user_inform(message) return api_response(message)
def update_multi(): """ 批量更新 """ # 查询用户列表 record = auth_db.query_user_lists(0, 2) modify_info = {} for ukey in record.keys(): modify_info[ukey] = {'password': str(time.time())} # # 批量插入 record = auth_db.update_multi_user(record, modify_info) return api_response(modify_info)
def insert_multi(): """ 批量插入 """ # 生成插入数据 modify_info = [] for index in range(0, 3): modify_info.append({ 'name': random_lower_str(10), 'password': random_lower_str(10), }) # 批量插入 record = auth_db.insert_multi_user(modify_info) return api_response(record)
def wrapper_fun(*args, **kwargs): # 解析url参数 effect, params = get_params(func.__module__, func.__name__, request.method) if effect == False: return api_response({ 'c': EC_GET_PARAMS_MISSING, 'msg': 'params_error' }) # 格式参数 if 'params' not in kwargs.keys(): kwargs['params'] = {} kwargs['params']['input'] = params return func(*args, **kwargs)
def get_users(): output = {'c': 0, 'users': []} query_time = redis_store.get('query_time') if query_time is None: query_time = time.time() redis_store.set('query_time', query_time, 3600) output['query_time'] = query_time user = User.query.all() for u in user: output['users'].append({'uid': u.uid, 'name': u.name}) session['time'] = time.time() return api_response(output)
def get_users(): output = { 'c': 0, 'users': [] } query_time = redis_store.get('query_time') if query_time is None: query_time = time.time() redis_store.set('query_time', query_time, 3600) output['query_time'] = query_time user = User.query.all() for u in user: output['users'].append({'uid': u.uid, 'name': u.name}) session['time'] = time.time() return api_response(output)
def wrapper_fun(*args, **kwargs): # 验证用户信息 name = session.get('name', None) if name is None: return redirect(url_for('auth.login')) # 解析url参数 effect, params = get_params(func.__module__, func.__name__, request.method) if effect == False: return api_response({ 'c': EC_GET_PARAMS_MISSING, 'msg': 'params_error' }) # 格式参数 if params: if 'params' not in kwargs.keys(): kwargs['params'] = {} kwargs['params']['input'] = params return func(*args, **kwargs)
def index(): return api_response({ 'flask_base': 'https://github.com/tlwlmy/flask_base', })
def update(params): record = auth_db.query_user_by_name(params['input']['name']) auth_db.update_user(record, params['input']) return api_response({'c'})