def home(): summary, temp = get_weather() user_id = current_user.id friends_objects = User.query.filter_by(id=user_id).first().friends notes_objects = User.query.filter_by(id=user_id).first().notes all_receivables = flatten( [friend.receivables for friend in friends_objects]) all_commitments = flatten( [friend.commitments for friend in friends_objects]) money = True if all_receivables or all_commitments else False receivables = flatten([friend.receivables for friend in friends_objects]) commitments = flatten([friend.commitments for friend in friends_objects]) receivable_sum = round( sum(receivable.amount for receivable in all_receivables), 2) commitment_sum = round( sum(commitment.amount for commitment in all_commitments), 2) money_summary = round(abs(receivable_sum - commitment_sum), 2) sums = (receivable_sum, commitment_sum, money_summary) return render_template('home.html', summary=summary, temp=temp, notes=notes_objects, money=money, receivables=receivables, commitments=commitments, sums=sums)
def receivables(): summary, temp = get_weather() notes_object = [] user_id = current_user.id if request.method == 'POST': friend_id = request.form.get('friend_id') title = request.form.get('reason') try: amount = request.form.get('how-much').replace(',', '.') amount = float(amount) except: flash('Enter valid amount!') return redirect(url_for('receivables')) new_receivable = Receivable( amount=amount, title=title, date=datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S'), friend_id=friend_id) db.session.add(new_receivable) db.session.commit() friends_objects = User.query.filter_by(id=user_id).first().friends all_receivables = [(friend.name, friend.receivables, sum(receivable.amount for receivable in friend.receivables)) for friend in friends_objects] return render_template('receivables.html', summary=summary, temp=temp, friends=friends_objects, all_receivables=all_receivables)
def weather(bot, update): """ To get weather of given location :param bot: :param update: :return weather information of user's location: """ user_location = get_user_location(update.message.from_user.id) if user_location: bot.send_message(chat_id=update.message.chat_id, text=get_weather(user_location[0])) else: bot.send_message(chat_id=update.message.chat_id, text=messages.location_msg)
def friends(): summary, temp = get_weather() user_id = current_user.id if request.method == 'POST': name = request.form.get('new-friend').strip() new_friend = Friend(name=name, user_id=user_id) db.session.add(new_friend) db.session.commit() return redirect(url_for('friends')) friends_objects = User.query.filter_by(id=user_id).first().friends return render_template('friends.html', summary=summary, temp=temp, friends=sorted(friends_objects, key=lambda x: x.name))
def notes(): summary, temp = get_weather() user_id = current_user.id if request.method == 'POST': content = request.form.get('new-note').strip() new_note = Note( content=content, user_id=user_id, date=datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S')) db.session.add(new_note) db.session.commit() return redirect(url_for('notes')) notes_objects = User.query.filter_by(id=user_id).first().notes return render_template('notes.html', summary=summary, temp=temp, notes=sorted(notes_objects, key=lambda x: x.date))
def home(): publication = get_value_with_fallback("publication") articles = get_news(publication) city = get_value_with_fallback('city') weather = get_weather(city) # get customised currency based on user input or default currency_from = get_value_with_fallback("currency_from") currency_to = get_value_with_fallback("currency_to") rate, currencies = get_rate(currency_from, currency_to) # save cookies and return template response = make_response( render_template("home.html", articles=articles, weather=weather, currency_from=currency_from, currency_to=currency_to, rate=rate, currencies=sorted(currencies))) expires = datetime.datetime.now() + datetime.timedelta(days=365) response.set_cookie("publication", publication, expires=expires) response.set_cookie("city", city, expires=expires) response.set_cookie("currency_from", currency_from, expires=expires) response.set_cookie("currency_to", currency_to, expires=expires) return response
async def handler(event: events.NewMessage.Event): weather = helpers.get_weather() await event.edit(weather)
async def handler(event): weather = helpers.get_weather() await event.edit(weather)