Beispiel #1
0
def add_alert():
    if request.method == "POST":
        name = request.form["name"]
        url = request.form['url']
        price_limit = float(request.form['price_limit'])

        try:
            if Item.url_validation(url):
                item = Item(name, url)
                item.save_item_data()
                alert = Alert(session['email'], item._id, price_limit)
                alert.check_price()
                return redirect(url_for("users.user_alerts"))
        except Errors.AlertErrors as e:
            return e.message

    return render_template("alerts/new_alert.html")
Beispiel #2
0
def edit_alert(alert_id):
    alert = Alert.find_by_id(alert_id)
    if request.method == "POST":
        price_limit = float(request.form["price_limit"])

        alert.price_limit = price_limit
        alert.save_alert_data()
        return redirect(url_for('users.user_alerts'))

    return render_template("alerts/edit_alert.html", alert=alert)
Beispiel #3
0
 def get_alerts(self):
     return Alert.find_by_email(self.email)
Beispiel #4
0
def delete_alert(alert_id):
    Alert.find_by_id(alert_id).delete()
    return redirect(url_for('users.user_alerts'))
Beispiel #5
0
def activate_alert(alert_id):
    Alert.find_by_id(alert_id).activate()
    return redirect(url_for('users.user_alerts'))
Beispiel #6
0
def check_actual_price(alert_id):
    Alert.find_by_id(alert_id).check_price()
    return redirect(url_for('.check_alert', alert_id=alert_id))
Beispiel #7
0
def check_alert(alert_id):
    alert = Alert.find_by_id(alert_id)
    return render_template("alerts/alert.html", alert=alert)
Beispiel #8
0
from project.models.alerts.alert import Alert
from project.common.database import Database

Database.initialize()

alerts_to_update = Alert.find_alerts_to_update()

for alert in alerts_to_update:
    alert.check_price()
    alert.send_email_alert()