Пример #1
0
def generate_playlist_cuesheet(djset, ext):
    cuesheet = """\
PERFORMER "{dj}"
TITLE "{date}"
""".format(
        dj=email.utils.quote(djset.dj.airname.encode("utf-8")), date=format_datetime(djset.dtstart, "%Y-%m-%d %H:%M")
    )

    delta = timedelta(hours=1)
    start = djset.dtstart.replace(minute=0, second=0, microsecond=0)
    end = djset.dtend.replace(minute=59, second=59, microsecond=0) + timedelta(seconds=1)
    offset = 0

    for loghour in perdelta(start, end, delta):
        tracks = (
            TrackLog.query.filter(
                db.and_(TrackLog.djset_id == djset.id, TrackLog.played >= loghour, TrackLog.played <= loghour + delta)
            )
            .order_by(TrackLog.played)
            .all()
        )

        if len(tracks) > 0:
            filename = datetime.strftime(localize_datetime(loghour), "%Y%m%d%H0001{}".format(ext))
            cuesheet += generate_cuesheet(filename, loghour, tracks, offset)
            offset += len(tracks)

    return cuesheet
Пример #2
0
def charts_bmi():
    if request.method == 'POST':
        start = dateutil.parser.parse(request.form['dtstart'])
        end = dateutil.parser.parse(request.form['dtend'])
        end = end.replace(hour=23, minute=59, second=59)

        f = io.BytesIO()
        writer = csv.writer(f)

        tracks = TrackLog.query.filter(TrackLog.played >= start,
                                       TrackLog.played <= end).all()
        for track in tracks:
            writer.writerow([
                app.config['TRACKMAN_NAME'],
                format_datetime(track.played),
                track.track.title.encode("utf8"),
                track.track.artist.encode("utf8")
            ])

        f.seek(0)

        filename = end.strftime("bmirep-%Y-%m-%d.csv")
        return send_file(f,
                         mimetype="text/csv",
                         as_attachment=True,
                         attachment_filename=filename)
    else:
        return render_template('admin/charts_bmi.html')
Пример #3
0
def list_archives(djset):
    start = djset.dtstart.replace(minute=0, second=0, microsecond=0)

    if djset.dtend is None:
        end = start
    else:
        end = djset.dtend.replace(minute=0, second=0, microsecond=0)

    for loghour in perdelta(start, end, timedelta(hours=1)):
        yield (
            app.config["ARCHIVE_BASE_URL"] + format_datetime(loghour, "%Y%m%d%H"),
            "-".join(
                [
                    format_datetime(loghour, "%Y-%m-%d %H:00"),
                    format_datetime(loghour + timedelta(hours=1), "%Y-%m-%d %H:00"),
                ]
            ),
        )
Пример #4
0
def email_playlist(djset):
    msg = MIMEMultipart("alternative")
    msg["Date"] = email.utils.formatdate()
    msg["From"] = app.config["MAIL_FROM"]
    msg["To"] = djset.dj.email
    msg["Message-Id"] = email.utils.make_msgid()
    msg["X-Mailer"] = "Trackman"
    msg["Subject"] = "[{name}] {djname} - Playlist from {dtend}".format(
        name=app.config["TRACKMAN_NAME"], djname=djset.dj.airname, dtend=format_datetime(djset.dtend, "%Y-%m-%d")
    )

    tracks = djset.tracks

    msg.attach(MIMEText(render_template("email/playlist.txt", djset=djset, tracks=tracks).encode("utf-8"), "text"))
    msg.attach(MIMEText(render_template("email/playlist.html", djset=djset, tracks=tracks).encode("utf-8"), "html"))

    s = smtplib.SMTP(app.config["SMTP_SERVER"])
    s.sendmail(msg["From"], [msg["To"]], msg.as_string())
    s.quit()