def server(env, expire): redis.set('env', env) redis.expire('env', expire) data = {} data['env'] = redis.get('env') data['expire'] = expire kformat(data) return redis.get('env')
def get_url(endpoint): env = ENV['DEFAULT_ENV'] if redis.get('env'): log.info('redis_ret={}'.format(redis.get('env').decode())) env = ENV[redis.get('env').decode()] log.info('env_ret={}'.format(env.HOST + ':' + env.PORT + '/' + env.ENDPOINT.get(endpoint))) return env.URL_FORMAT.format(host=env.HOST, port=env.PORT, endpoint=env.ENDPOINT[endpoint])
def upload(content, type, descr, attr): data = {'content': content, 'type': type, 'descr': descr, 'attr': ''} tmp = {} for item in attr: tmp[item[0]] = item[1] data['attr'] = json.dumps(tmp) ret = post(get_url('upload'), data=data, cookies={'session_id': redis.get('session').decode()}) data['message'] = ret.json()['message'] kformat(data) return ret.text
def update(content, descr, attr, mid, status): data = { 'content': content, 'descr': descr, 'status': status, 'attr': '', 'mid': mid, } tmp = {} for item in attr: tmp[item[0]] = item[1] data['attr'] = json.dumps(tmp) ret = put(get_url('update'), data=data, cookies={'session_id': redis.get('session').decode()}) kformat(data) return ret.text
def gmes(type, attr): data = {'type': type} tmp = {} for item in attr: tmp[item[0]] = item[1] data['attr'] = json.dumps(tmp) ret = get(get_url('gmes'), data=data, cookies={'session_id': redis.get('session').decode()}) result = {} result['code'] = ret.json()['code'] result['message'] = ret.json()['message'] result.update(data) kformat(result, title='args and descr') head_list = [('类型', 'type'), ('内容', 'content'), ('创建时间', 'create_time'), ('ID', 'id'), ('状态', 'status')] lformat(ret.json()['data']['messages'], head_list) return ret.text