Export played tracks csv works
This commit is contained in:
parent
63acc025f9
commit
9485b244f5
@ -249,13 +249,20 @@ class Playdates(Base):
|
||||
return last_played[0]
|
||||
else:
|
||||
return None
|
||||
#
|
||||
# @staticmethod
|
||||
# def played_after(session: Session, since: datetime) -> List["Playdates"]:
|
||||
# """Return a list of Playdates objects since passed time"""
|
||||
#
|
||||
# return session.query(Playdates).filter(
|
||||
# Playdates.lastplayed >= since).all()
|
||||
|
||||
@staticmethod
|
||||
def played_after(session: Session, since: datetime) -> List["Playdates"]:
|
||||
"""Return a list of Playdates objects since passed time"""
|
||||
|
||||
return (
|
||||
session.execute(
|
||||
select(Playdates)
|
||||
.where(Playdates.lastplayed >= since)
|
||||
.order_by(Playdates.lastplayed)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
#
|
||||
# @staticmethod
|
||||
# def remove_track(session: Session, track_id: int) -> None:
|
||||
|
||||
@ -7,14 +7,13 @@ import sys
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
# from typing import Callable, Dict, List, Optional, Tuple
|
||||
#
|
||||
# from PyQt5.QtCore import QDate, QProcess, Qt, QTime, QTimer, QUrl
|
||||
from PyQt5.QtCore import QEvent, Qt, QTimer
|
||||
|
||||
from PyQt5.QtCore import QDate, QEvent, Qt, QTime, QTimer
|
||||
from PyQt5.QtGui import QColor
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog,
|
||||
# QFileDialog,
|
||||
QFileDialog,
|
||||
# QInputDialog,
|
||||
QLabel,
|
||||
# QLineEdit,
|
||||
@ -39,7 +38,7 @@ from playlists import PlaylistTab
|
||||
from sqlalchemy.orm.exc import DetachedInstanceError
|
||||
# from ui.dlg_search_database_ui import Ui_Dialog
|
||||
from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist # type: ignore
|
||||
# from ui.downloadcsv_ui import Ui_DateSelect
|
||||
from ui.downloadcsv_ui import Ui_DateSelect # type: ignore
|
||||
from config import Config
|
||||
from ui.main_window_ui import Ui_MainWindow # type: ignore
|
||||
# from utilities import create_track_from_file, update_db
|
||||
@ -171,8 +170,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# self.actionAdd_note.triggered.connect(self.create_note)
|
||||
self.action_Clear_selection.triggered.connect(self.clear_selection)
|
||||
self.actionClosePlaylist.triggered.connect(self.close_playlist_tab)
|
||||
# self.actionDownload_CSV_of_played_tracks.triggered.connect(
|
||||
# self.download_played_tracks)
|
||||
self.actionDownload_CSV_of_played_tracks.triggered.connect(
|
||||
self.download_played_tracks)
|
||||
# ***kae
|
||||
self.actionEnable_controls.triggered.connect(
|
||||
self.enable_play_next_controls)
|
||||
# self.actionExport_playlist.triggered.connect(self.export_playlist_tab)
|
||||
@ -275,32 +275,32 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.actionPlay_next.setEnabled(False)
|
||||
self.statusbar.showMessage("Play controls: Disabled", 0)
|
||||
#
|
||||
# def download_played_tracks(self) -> None:
|
||||
# """Download a CSV of played tracks"""
|
||||
#
|
||||
# dlg = DownloadCSV(self)
|
||||
# if dlg.exec():
|
||||
# start_dt = dlg.ui.dateTimeEdit.dateTime().toPyDateTime()
|
||||
# # Get output filename
|
||||
# pathspec: Tuple[str, str] = QFileDialog.getSaveFileName(
|
||||
# self, 'Save CSV of tracks played',
|
||||
# directory="/tmp/playlist.csv",
|
||||
# filter="CSV files (*.csv)"
|
||||
# )
|
||||
# if not pathspec:
|
||||
# return
|
||||
#
|
||||
# path: str = pathspec[0]
|
||||
# if not path.endswith(".csv"):
|
||||
# path += ".csv"
|
||||
#
|
||||
# with open(path, "w") as f:
|
||||
# with Session() as session:
|
||||
# for playdate in Playdates.played_after(session, start_dt):
|
||||
# f.write(
|
||||
# f"{playdate.track.artist},{playdate.track.title}\n"
|
||||
# )
|
||||
|
||||
def download_played_tracks(self) -> None:
|
||||
"""Download a CSV of played tracks"""
|
||||
|
||||
dlg = DownloadCSV(self)
|
||||
if dlg.exec():
|
||||
start_dt = dlg.ui.dateTimeEdit.dateTime().toPyDateTime()
|
||||
# Get output filename
|
||||
pathspec = QFileDialog.getSaveFileName(
|
||||
self, 'Save CSV of tracks played',
|
||||
directory="/tmp/playlist.csv",
|
||||
filter="CSV files (*.csv)"
|
||||
)
|
||||
if not pathspec:
|
||||
return
|
||||
|
||||
path = pathspec[0]
|
||||
if not path.endswith(".csv"):
|
||||
path += ".csv"
|
||||
|
||||
with open(path, "w") as f:
|
||||
with Session() as session:
|
||||
for playdate in Playdates.played_after(session, start_dt):
|
||||
f.write(
|
||||
f"{playdate.track.artist},{playdate.track.title}\n"
|
||||
)
|
||||
#
|
||||
# def drop3db(self) -> None:
|
||||
# """Drop music level by 3db if button checked"""
|
||||
@ -974,18 +974,18 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# item = self.ui.matchList.currentItem()
|
||||
# track = item.data(Qt.UserRole)
|
||||
# self.ui.dbPath.setText(track.path)
|
||||
#
|
||||
#
|
||||
# class DownloadCSV(QDialog):
|
||||
# def __init__(self, parent=None):
|
||||
# super().__init__(parent)
|
||||
#
|
||||
# self.ui = Ui_DateSelect()
|
||||
# self.ui.setupUi(self)
|
||||
# self.ui.dateTimeEdit.setDate(QDate.currentDate())
|
||||
# self.ui.dateTimeEdit.setTime(QTime(19, 59, 0))
|
||||
# self.ui.buttonBox.accepted.connect(self.accept)
|
||||
# self.ui.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
|
||||
class DownloadCSV(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.ui = Ui_DateSelect()
|
||||
self.ui.setupUi(self)
|
||||
self.ui.dateTimeEdit.setDate(QDate.currentDate())
|
||||
self.ui.dateTimeEdit.setTime(QTime(19, 59, 0))
|
||||
self.ui.buttonBox.accepted.connect(self.accept)
|
||||
self.ui.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
|
||||
class SelectPlaylistDialog(QDialog):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user