def create_alert() -> str: logger.debug('Received request: {}'.format(request.method)) if request.method == 'POST': name = request.form['name'] url = request.form['url'] price = float(request.form['price']) item = Item(name=name, url=url) item.load_price(update_in_database=True) alert = Alert(item_id=item._id, price_threshold=price, user_email=session['email']) alert.insert_into_database() return render_template('alerts/new_alert.html')
def index() -> str: email = session['email'] if email is not None: alerts = Alert.find_by_email(email=email) return render_template('alerts/alerts.html', alerts=alerts) return render_template('alerts/message.html')
def load_item_price(alert_id: str) -> str: alert = Alert.find_one_by_id(_id=alert_id) if not alert: logger.error( 'Alert ID {} not found in order to load price'.format(alert_id)) return redirect(location=url_for(endpoint='.')) alert.refresh() return redirect( location=url_for(endpoint='.get_alert_page', alert_id=alert_id))
def edit_alert(alert_id: str) -> str: alert = Alert.find_one_by_id(_id=alert_id) if request.method == 'POST': price = float(request.form['price']) alert.price_threshold = price alert.update_in_database(upsert=False) return redirect( location=url_for(endpoint='.get_alert_page', alert_id=alert._id)) return render_template('alerts/edit_alert.html', alert=alert)
def get_alert_page(alert_id: str) -> str: alert = Alert.find_one_by_id(_id=alert_id) return render_template('alerts/alert.html', alert=alert)
def delete_alert(alert_id: str) -> str: logger.debug('Delete alert: {}'.format(alert_id)) Alert.remove_alert(alert_id=alert_id) return redirect(location=url_for(endpoint='.'))
def activate_alert(alert_id: str) -> str: logger.debug('Activate alert: {}'.format(alert_id)) alert = Alert.find_one_by_id(_id=alert_id) alert.activate() return redirect( location=url_for(endpoint='.get_alert_page', alert_id=alert_id))
from pricing.src.models.alerts.alert import Alert from pricing.src.common.logging_base import Logging import pricing logger = Logging.create_rotating_log( module_name=__name__, logging_directory=pricing.configuration['logging_directory']) alerts_to_update = Alert.get_alerts_to_update() logger.debug('Alerts to update: {}'.format(alerts_to_update)) for alert in alerts_to_update: alert.send_email_if_price_reached()