示例#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 send_game_alert(user_id):
    """Checks to see if any of the user's preferences have met the set threshold
    prices and sends an email with the complete list of those preferences."""
    user_preferences = Preferences.query.filter_by(user_id=user_id)
    user_email = User.query.filter_by(id=user_id).first().email

    if user_preferences.first():
        game_alerts = []
        for preference in user_preferences:
            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)])
        if game_alerts:
            with app.app_context():
            # find_template = Environment(loader=PackageLoader("SteamScout", "templates/email"))
            # template = find_template.get_template("scout_alert.html")
            # preferences_url = url_for('settings', _external=True)
            # html = template.render(game_alerts=game_alerts)
                html = render_template("email/scout_alert.html", game_alerts=game_alerts)
                subject = "Scout Report"
                send_mail(user_email, subject, html)