def lambda_handler(event, context): """Update a users current location Parameters ---------- event: dict, required API Gateway Lambda Proxy Input Format context: object, required Lambda Context runtime methods and attributes Returns ------ API Gateway Lambda Proxy Output Format: dict """ try: request = decode(event) except (json.JSONDecodeError, ValidationError): return responses.invalid() users = db.get_user_by_id(request.user_id) if len(users) == 0: return responses.not_found(request.user_id) if len(users) > 1: return responses.server_error() db.update_user_loc(request.user_id, request.lat, request.lon) return responses.success()
def wrap(*args, **kwargs): id = kwargs.get('id', 0) task = Task.query.filter_by(id=id).first() if task is None: return not_found() return function(task)
def pass_through(): try: r = Resizer( current_app.config['REDIS'], current_app.config['IMAGE_DIR'], statsd_config=current_app.config['STATSD'], key_expire=current_app.config['REDIS_KEY_EXPIRE'] ) result = r.process_and_return(request.args) if result: return Response(result, mimetype='image/jpeg') return responses.not_found() except KeyError, e: return responses.bad_argument(e.message)
def token(t): data = int(t) u = User.query.filter_by(id=data).first() if not u: return not_found('url not found') if session.get('has_click_for_user_' + str(data), -1) == data: flash(u'你已经为该用户砍价过了') return redirect(url_for('.index')) session['has_click_for_user_' + str(data)] = data if u.price > 10: u.price = u.price - 10 else: u.price = 0 db.session.add(u) db.session.commit() flash(u'为好友砍价成功') return redirect(url_for('.index'))
async def search(*args, **kwargs): logging.info(f'Recieved {kwargs}') stat_funcs = { 'most_used_word': _get_most_used_word, 'word_frequency': _get_word_frequency, } func = stat_funcs[kwargs['stat']] params = {} query = WordCloud.query words = await query.gino.all() words_dump = [word.dump() for word in words] params['words'] = words_dump if words is None: return responses.not_found() else: response = await func(params) return responses.get(response)
async def search(*args, **kwargs): articles = [] articles_dump = None search = None if 'search' in kwargs: search = str(kwargs['search']) async with db.bind.acquire() as conn: query = NewsArchive.query if search: words = search.split(' ') for word in words: query.append_whereclause( NewsArchive.description.contains(word) ) articles_count = await conn.scalar(query.alias().count()) query = query.limit( kwargs['page_size'] ).offset( kwargs['page'] * kwargs['page_size'] ).order_by( NewsArchive.date_published.desc() ) articles = await conn.all(query) if articles is None: return responses.not_found() else: article_dump = [article.dump() for article in articles] return responses.search(articles_count, article_dump)