Exemple #1
0
def disable_automation():
    automation_enabled = redis_conn.get("automation_enabled")
    # Make sure automation is actually enabled before changing the end time
    if automation_enabled is not None and automation_enabled == "true":
        redis_conn.set("automation_enabled", "false")
        automation_set_id = redis_conn.get("automation_set")
        app.logger.info("Automation disabled with DJSet.id = {}".format(automation_set_id))
        if automation_set_id is not None:
            automation_set = DJSet.query.get(int(automation_set_id))
            automation_set.dtend = datetime.utcnow()
            db.session.commit()
Exemple #2
0
    def dj_wrapper(*args, **kwargs):
        # Call in the function first incase it changes the timeout
        ret = f(*args, **kwargs)

        redis_conn.set('dj_active', 'true')
        # logout/login must delete this dj_timeout
        expire = redis_conn.get('dj_timeout')
        if redis_conn.get('dj_timeout') is None:
            expire = app.config['DJ_TIMEOUT']

        redis_conn.expire('dj_active', int(expire))

        return ret
Exemple #3
0
def start_automation():
    automation = redis_conn.get('automation_enabled') == "true"
    if not automation:
        logout_all()
        enable_automation()

    return redirect(url_for('trackman.login'))
Exemple #4
0
def autologout_check():
    active = redis_conn.get("dj_active")
    automation = redis_conn.get("automation_enabled")
    # active is None if dj_active has expired (no activity)
    if active is None:
        if automation is None:
            # This should never happen
            pass
        elif automation == "true":
            # automation is running, carry on
            # if automation is enabled, enable_automation was already called
            pass
        else:
            # Automation is not running, end djset if exists and start
            # automation
            logout_all()
            enable_automation()
Exemple #5
0
def submit_automation_track():
    if 'password' not in request.form or \
            request.form['password'] != app.config['AUTOMATION_PASSWORD']:
        abort(403)

    automation = redis_conn.get('automation_enabled') == "true"
    if not automation:
        return Response("Automation is off\n", mimetype="text/plain")

    if 'title' in request.form and len(request.form['title']) > 0:
        title = request.form['title'].strip()
    else:
        title = "Not Available"

    if 'artist' in request.form and len(request.form['artist']) > 0:
        artist = request.form['artist'].strip()
    else:
        artist = "Not Available"

    if 'album' in request.form and len(request.form['album']) > 0:
        album = request.form['album'].strip()
    else:
        album = "Not Available"

    if artist.lower() in ("wuvt", "pro", "soo", "psa", "lnr", "ua"):
        # ignore PSAs and other traffic
        return Response("Will not log traffic\n", mimetype="text/plain")

    if 'label' in request.form and len(request.form['label']) > 0:
        label = request.form['label'].strip()
        tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album).filter(Track.label == label)
        if len(tracks.all()) == 0:
            track = Track(title, artist, album, label)
            db.session.add(track)
            db.session.commit()
        else:
            track = tracks.one()

    else:
        # Handle automation not providing a label
        label = "Not Available"
        tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album)
        if len(tracks.all()) == 0:
            track = Track(title, artist, album, label)
            db.session.add(track)
            db.session.commit()
        else:
            notauto = tracks.filter(Track.label != "Not Available")
            if len(notauto.all()) == 0:
                # The only option is "not available label"
                track = tracks.one()
            else:
                track = notauto.one()

    log_track(track.id, None)

    return Response("Logged\n", mimetype="text/plain")
def load_premiums_config():
    premiums_config = redis_conn.get('donate_premiums_config')
    if premiums_config is not None:
        try:
            data = json.loads(premiums_config)
        except json.JSONDecodeError:
            data = {}
    else:
        data = {}

    if 'enabled' not in data:
        data['enabled'] = False

    return data
Exemple #7
0
def change_autologout():
    if request.method == 'GET':
        dj_timeout = redis_conn.get('dj_timeout')
        if dj_timeout is None:
            return jsonify(success=True, autologout=True)
        else:
            return jsonify(success=True, autologout=False)
    elif request.method == 'POST':
        if 'autologout' not in request.form:
            return jsonify(success=False, error='No autologout field given in POST')
        if request.form['autologout'] == 'enable':
            redis_conn.delete('dj_timeout')
            # This needs to be reexpired now since dj_timeout changed after dj_interact
            return jsonify(success=True, autologout=True)
        else:
            redis_conn.set('dj_timeout', app.config['EXTENDED_DJ_TIMEOUT'])
            return jsonify(success=True, autologout=False)
Exemple #8
0
def login():
    if 'dj' in request.form and len(request.form['dj']) > 0:
        disable_automation()

        dj = DJ.query.get(request.form['dj'])

        # close open DJSets, and see if we have one we can use
        djset = logout_all_but_current(dj)
        if djset is None:
            djset = DJSet(dj.id)
            db.session.add(djset)
            db.session.commit()

        return redirect(url_for('trackman.log', setid=djset.id))

    automation = redis_conn.get('automation_enabled') == "true"

    djs = DJ.query.filter(DJ.visible == True).order_by(DJ.airname).all()
    return render_template('trackman/login.html',
                           trackman_name=app.config['TRACKMAN_NAME'],
                           automation=automation, djs=djs)
Exemple #9
0
def donation_index():
    if not app.config['DONATE_ENABLE']:
        abort(404)

    if request.method == 'POST':
        if 'reset_stats' in request.form:
            redis_conn.set('donation_stats_start',
                           datetime.datetime.utcnow().isoformat())
        return redirect(url_for('.donation_index'))

    stats = Order.query.with_entities(
        db.func.sum(Order.amount).label('total_paid'),
        db.func.max(Order.amount).label('max_paid'))

    donation_stats_start = redis_conn.get('donation_stats_start')
    if donation_stats_start is not None:
        last_stats_reset = dateutil.parser.parse(donation_stats_start)
        stats = stats.filter(Order.placed_date > last_stats_reset)
    else:
        last_stats_reset = None

    stats = stats.all()

    total = stats[0][0]
    if total is None:
        total = 0

    max_donation = stats[0][1]
    if max_donation is None:
        max_donation = 0

    donations = Order.query.all()

    return render_template('admin/donation_index.html',
                           donations=donations,
                           total=total,
                           max=max_donation,
                           last_stats_reset=last_stats_reset)
Exemple #10
0
def automation_log():
    if 'password' not in request.form or \
            request.form['password'] != app.config['AUTOMATION_PASSWORD']:
        return jsonify(success=False, error="Invalid password")

    automation = redis_conn.get('automation_enabled') == "true"
    if not automation:
        return jsonify(success=False, error="Automation not enabled")

    if 'title' in request.form and len(request.form['title']) > 0:
        title = request.form['title'].strip()
    else:
        title = "Not Available"

    if 'artist' in request.form and len(request.form['artist']) > 0:
        artist = request.form['artist'].strip()
    else:
        artist = "Not Available"

    if 'album' in request.form and len(request.form['album']) > 0:
        album = request.form['album'].strip()
    else:
        album = "Not Available"

    if artist.lower() in ("wuvt", "pro", "soo", "psa", "lnr", "ua"):
        # TODO: implement airlog logging
        return jsonify(success=False,
                       error='AirLog logging not yet implemented')

    if 'label' in request.form and len(request.form['label']) > 0:
        label = request.form['label'].strip()
        tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album).filter(Track.label == label)
        if len(tracks.all()) == 0:
            track = Track(title, artist, album, label)
            db.session.add(track)
            db.session.commit()
        else:
            track = tracks.first()

    else:
        # Handle automation not providing a label
        label = "Not Available"
        tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album)
        if len(tracks.all()) == 0:
            track = Track(title, artist, album, label)
            db.session.add(track)
            db.session.commit()
        else:
            notauto = tracks.filter(Track.label != "Not Available")
            if len(notauto.all()) == 0:
                # The only option is "not available label"
                track = tracks.first()
            else:
                track = notauto.first()

    djset_id = redis_conn.get('automation_set')
    if djset_id != None:
        djset_id = int(djset_id)
    log_track(track.id, djset_id)

    return jsonify(success=True)