Пример #1
0
def send_game_alerts():
    user_preferences = Preferences.query.all()
    user_email = User.query.filter
    
    for user in User.query.all():
        user_id = user.id
        user_email = user.email
        user_validated = user.validated
        user_preferences = Preferences.query.filter_by(user_id=user_id)

        if user_preferences.first() and user_validated:
            game_alerts = []
            for preference in user_preferences:
                if not preference.notification_sent:
                    current_game_info = get_price_info(preference.game_id)
                    if preference.threshold_amount >= current_game_info["current_price"]/100.0:
                        game_alerts.append([preference.game_name, "${:.2f}".format(preference.threshold_amount)])
                        preference.notification_sent = True #
                        db.session.add(preference)
                        db.session.commit()
            if game_alerts:
                with app.app_context():
                    html = render_template("email/scout_alert.html", game_alerts=game_alerts)
                    subject = "Scout Report"
                    send_mail(user_email, subject, html)
    print "send_game_alerts() executed."
Пример #2
0
def game_name(game_name):
    title = game_name
    game = Games.query.filter_by(game_name=game_name).first()

    id_num = game.game_id
    amount_form = AmountPref()
    if 'user_id' in session.keys():
        try:
            preference = Preferences.query.filter_by(
                game_name=game_name, user_id=session['user_id']).first()
            existing_treshold = "{:.2f}".format(preference.threshold_amount)
        except:
            existing_treshold = None
    else:
        existing_treshold = None

    price_info = get_price_info(id_num)
    if price_info != None:
        current_price = format_price(price_info['current_price'])
        initial_price = format_price(price_info['initial_price'])
        discount = price_info['discount_percent']
        header_image = price_info['header_image']
    else:
        current_price, initial_price, discount, header_image = None, None, None, None
    if amount_form.validate_on_submit():
        user = User.query.filter_by(id=session['user_id']).first()
        if not user.validated:
            flash(
                "You will not receieve any email alerts until you activate your account.",
                "danger")
        if preference:
            old_preference = Preferences.query.filter_by(
                game_name=game_name).first()
            db.session.delete(old_preference)
            db.session.commit()

        new_preference = Preferences(session['user_id'], id_num, title,
                                     amount_form.threshold_amount.data)
        db.session.add(new_preference)
        db.session.commit()
        return redirect(url_for('settings'))

    return render_template(
        'game_page.html',
        current_price=current_price,
        initial_price=initial_price,
        discount=discount,
        game_title=title,
        id_num=id_num,
        header_image=header_image,
        amount_form=amount_form,
        preference=existing_treshold)