Exemplo n.º 1
0
def ticker_alerts():
    with app.app_context():
        app.logger.debug("Processing Alerts ...")
        for alert in Alert.objects(active=True):
            app.logger.debug("Processing Alert: {}".format(alert.id))
            if alert_meets_price_criteria(alert):
                alert_trigger(alert)
Exemplo n.º 2
0
def alert_edit(hash):
    alert = Alert.objects(hash=hash).first()
    if not alert:
        flash("Such alert doesn' exists")
        return redirect(url_for('alerts'))

    form = AlertForm()
    if request.method == 'POST' and form.validate():
        if not form.currency.data in supported_currencies(
                exchange=form.exchange.data):
            flash("{} doesn\\'t support {}".format(form.exchange.data,
                                                   form.currency.data))
            return redirect(url_for('alert_edit', hash=hash))

        if not form.cryptocurrency.data in supported_cryptocurrencies(
                exchange=form.exchange.data):
            flash("{} doesn\\'t support {}".format(form.exchange.data,
                                                   form.cryptocurrency.data))
            return redirect(url_for('alert_edit', hash=hash))

        alert.method = form.method.data
        alert.method_data = form.method_data.data
        alert.cryptocurrency = form.cryptocurrency.data
        alert.price_direction = form.price_direction.data
        alert.price = form.price.data
        alert.currency = form.currency.data
        alert.exchange = form.exchange.data
        alert.note = form.note.data
        alert.resend_after = resend_after_to_seconds(form.resend_after.data)
        alert.notify_only_once = form.notify_only_once.data

        if alert_meets_price_criteria(alert):
            flash(
                "{} price ${} {} is already {} ${} {} on {}, retry with new parameters"
                .format(
                    alert.cryptocurrency,
                    get_current_price(alert.exchange, alert.currency,
                                      alert.cryptocurrency), alert.currency,
                    alert.price_direction, alert.price, alert.currency,
                    alert.exchange))
            return redirect(url_for('alert_edit', hash=hash))

        alert.save()
        flash('Changes saved!')
        return redirect(url_for('alerts'))

    forms = alert_forms()
    forms['alert'].method.data = alert.method
    forms['alert'].method_data.data = alert.method_data
    forms['alert'].cryptocurrency.data = alert.cryptocurrency
    forms['alert'].price_direction.data = alert.price_direction
    forms['alert'].price.data = alert.price
    forms['alert'].currency.data = alert.currency
    forms['alert'].exchange.data = alert.exchange
    forms['alert'].note.data = alert.note
    forms['alert'].resend_after.data = seconds_to_resend_after(
        alert.resend_after)
    forms['alert'].notify_only_once.data = alert.notify_only_once

    return render_template("alert.edit.html.j2", forms=forms, hash=hash)
Exemplo n.º 3
0
def alert_meets_max_emails_criteria(alert):
    if len(Alert.objects(
            user=alert.user,
            active=True)) >= app.config['APP_MAX_ALERTS_PER_MONTH']:
        if not alert.user.is_mod():
            return False

    return True
Exemplo n.º 4
0
def alert_delete(hash):
    alert = Alert.objects(hash=hash).first()
    if not alert:
        flash("Such alert doesn' exists")
        return redirect(url_for('alerts'))

    alert.delete()
    flash('Alert deleted sucessfully')
    return redirect(url_for('alerts'))
Exemplo n.º 5
0
def alert_toggle_state(hash):
    alert = Alert.objects(hash=hash).first()
    if not alert:
        flash("Such alert doesn' exists")
        return redirect(url_for('alerts'))

    if not alert.active and not alert_meets_max_emails_criteria(alert):
        flash("Max amount of active alerts reached: {}".format(
            app.config['APP_MAX_ALERTS_PER_MONTH']))
        return redirect(url_for('terms_of_service'))

    alert.active = not alert.active
    alert.save(clean=False)
    return redirect(url_for('alerts'))
Exemplo n.º 6
0
def alert_report(hash):
    alert = Alert.objects(hash=hash).first()
    if not alert:
        flash("Such alert doesn' exists")
        return redirect(url_for('index'))

    alert.active = False
    alert.user.spam_strikes += 1
    if alert.user.spam_strikes == app.config['APP_MAX_ALERTS_SPAM_STRIKES']:
        alert.user.suspend()
    alert.save()
    flash(
        "The reported alert has been disabled and the infractor notified, sorry for the inconvience!"
    )
    return redirect(url_for('index'))