def list_hot_user(): page = request.args.get('page', 1) per_page = request.args.get('pageCount', 10) pagination = UserInfo.query.paginate(page=page, per_page=per_page) items = pagination.items data = [] if items: data = [{ 'user_id': user.id, 'nickname': user.nickname, 'birthday': user.format_birthday(), 'gender': user.gender, 'avatar': user.avatar, 'height': user.height, 'sexual': user.sexual, 'education': user.education, 'salary': user.salary, 'emotion': user.emotion } for user in items] obj = { 'total': pagination.total, 'list': data, 'has_next': pagination.has_next } return make_response_ok(obj)
def show_user_info(): uid = request.args.get('userId') peer_id = request.args.get('peerId') show_id = uid if peer_id: show_id = peer_id user = get_user_with_cache(show_id) if not user: return make_response_error(501, 'user not found') data = { 'user_id': user.id, 'nickname': user.nickname, 'birthday': user.birthday, 'gender': user.gender, 'avatar': user.avatar, 'height': user.height, 'sexual': user.sexual, 'education': user.education, 'salary': user.salary, 'emotion': user.emotion } if show_id == uid: data['phone'] = user.phone return make_response_ok(data)
def send_sms(): phone = request.form.get('phone') m = re.match(pattern_phone, phone) if not m: return make_response_error(300, 'phone number format error.') # 这里需要修改为对接短信服务 code = '97532' key = f'{phone}-{code}' r.set(key, code, 60) return make_response_ok({'phone': phone, 'code': code})
def kline(symbol): # exchange_name = request.args.get('ex') # symbol = request.args.get('symbol') timeframes = request.args.get('tf') # timeframes # params = {'partial': False} exchange = create_exchange('ex') #since = int(start.timestamp()*1000) time.sleep(exchange.rateLimit / 1000) if exchange.has['fetchOHLCV']: return make_response_ok(exchange.fetch_ohlcv(symbol, timeframes))
def list_nearby_user(): latlng = request.args.get('latlng', '') logging.info(f'remote ip : {request.remote_addr}') location = latlng.split(',') if len(location) <= 1: return make_response_error(502, 'lat,lng error') lat, lng = location data = {'longitude': lng, 'latitude': lat} return make_response_ok(data)
def update_user(): uid = request.form.get('userId', '') nickname = request.form.get('nickname') if not check_nickname(nickname): return make_response_error( 505, 'the length of nickname must larger than 5 and less thad 8') email = request.form.get('email') gender = request.form.get('gender', default=0, type=int) if gender > 2 or gender < 0: gender = 0 sexual = request.form.get('sexual', default=0, type=int) if sexual > 2 or sexual < 0: sexual = 0 height = request.form.get('height', type=int) education = request.form.get('education', type=int) emotion = request.form.get('emotion', type=int) salary = request.form.get('salary', type=int) birthday = request.form.get('birthday', type=str) avatar = request.form.get('avatar', type=str) if birthday: birthday = datetime.strptime(birthday, "%Y-%m-%d") user: UserInfo = get_user_with_cache(uid) user.nickname = nickname user.emotion = emotion user.email = email user.gender = gender user.sexual = sexual user.height = height user.education = education user.salary = salary user.birthday = birthday user.avatar = avatar db.session.commit() return make_response_ok(data={"data": user.id})
def login(): phone = request.form.get('phone') code = request.form.get('code') key = f'{phone}-{code}' sms_code = r.get(key) if sms_code: sms_code = sms_code.decode() if code != sms_code: return make_response_error(503, 'sms code error') auth_info = UserAuth.query.filter_by(open_id=phone).first() if not auth_info: auth_info = register_by_phone(phone) else: auth_info = login_by_phone(auth_info) data = { 'token': auth_info.token, 'expire_time': auth_info.expired_time.strftime("%Y-%m-%d %H:%M:%S"), 'user_id': auth_info.user_basic.id } r.set(f'auth_info_{auth_info.user_id}', str(data)) return make_response_ok(data)
def exchanges(): # 列出所有交易所 return make_response_ok(ccxt.exchanges)
def item(exchange, attr): exchange = create_exchange(exchange) exchange.load_markets() data = getattr(exchange, attr) return make_response_ok(data)
def order(symbol): exchange = create_exchange('ex') order_book = exchange.fetch_order_book(symbol) return make_response_ok(order_book)
def trades(symbol): # limit = request.args.get('limit') exchang = create_exchange('ex') trades = exchang.fetch_trades(symbol) return make_response_ok(trades)
def ticker(symbol): # exchange_name = request.args.get('ex') exchange = create_exchange('ex') ticker = exchange.fetch_ticker(symbol) return make_response_ok(ticker)