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")
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)
def get_alerts(self): return Alert.find_by_email(self.email)
def delete_alert(alert_id): Alert.find_by_id(alert_id).delete() return redirect(url_for('users.user_alerts'))
def activate_alert(alert_id): Alert.find_by_id(alert_id).activate() return redirect(url_for('users.user_alerts'))
def check_actual_price(alert_id): Alert.find_by_id(alert_id).check_price() return redirect(url_for('.check_alert', alert_id=alert_id))
def check_alert(alert_id): alert = Alert.find_by_id(alert_id) return render_template("alerts/alert.html", alert=alert)
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()