Skip to content

Commit

Permalink
Merge pull request #1 from Feuer-sturm/Add-json-to-xlsx-converter
Browse files Browse the repository at this point in the history
Add json to xlsx converter
  • Loading branch information
Feuer-sturm authored Jan 8, 2024
2 parents 439682e + 9ab7815 commit a988f7b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
/*.json
/*.xlsx
42 changes: 42 additions & 0 deletions MuPiBox-MusikVerwaltung-json2xlsx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json
from openpyxl import Workbook

INPUTFILE = 'data.json'
OUTPUTFILE = 'MuPiBox_MusikVerwaltung_Template.xlsx'

documentation = [
'x = Eintrag wird in data.json hinzugefügt',
'',
'',
'Audibook und Music:',
'Audibook und Music:',
'Audibook und Music: Wert nur setzen, wenn aPartofAll = true ist',
'Audibook und Music: Wert nur setzen, wenn aPartofAll = true ist',
'Audibook und Music: Name für Album / Sammlung',
'Audibook und Music: Artistid aus Spotify eines Künstlers',
'Audibook: ID für Podcasts',
'Audibook und Music: Spotify Query Syntax',
'Audibook und Music: Attribut für "Menü Audibook und Music" -> "opt. Artist Cover"',
'Audibook und Music: In diesem Attribut muss die ID eingetragen werden, wenn es sich um eine Playlist handelt',
'Audibook und Music + Radio: AlbumID oder Stream Link',
'Radio: Attribut für "Menü Radio" -> "Title". Ist der Titel für den Stream',
'Radio: Attribut für "Menü Radio" -> "Cover Artwork URL"',
'Interner Kommentar, welcher nicht in die data.json integriert wird',
'Interner Kommentar, welcher nicht in die data.json integriert wird'
]
labels = ['add to file', 'type', 'category', 'shuffle', 'aPartOfAll', 'aPartOfAllMin', 'aPartOfAllMax', 'artist',
'artistid', 'showid', 'query', 'artistcover', 'playlistid', 'id', 'title', 'cover', 'Kommentar', 'url']

wb = Workbook()
ws = wb.active

ws.append(documentation)
ws.append(labels)

with open(INPUTFILE, 'r', encoding='utf-8') as file:
json_data = json.load(file)
for json_entry in json_data:
json_entry['add to file'] = 'x' # extend the dictionary with this field to generate an 'x' for this entry in the table
table_entry = [json_entry.get(label, '') for label in labels] # if a label doesn't exist in the json_entry, the value defaults to ''
ws.append(table_entry)
wb.save(OUTPUTFILE)
14 changes: 10 additions & 4 deletions MuPiBox-MusikVerwaltung-xlsx2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from openpyxl import load_workbook
from openpyxl.utils import get_column_letter

FILEPATH = 'MuPiBox_MusikVerwaltung_Template.xlsx'
INPUTFILE = 'MuPiBox_MusikVerwaltung_Template.xlsx'
OUTPUTFILE = 'data.json'

wb = load_workbook(filename=FILEPATH)
wb = load_workbook(filename=INPUTFILE)
ws = wb.active
my_list = []

Expand All @@ -21,10 +22,15 @@
for column in range(FIRST_COLUMN, LAST_COLUM + 1):
column_letter = get_column_letter(column)
if row > FIRST_ROW and ws[column_letter + str(row)].value is not None :
my_dict[ws[column_letter + str(FIRST_ROW)].value] = ws[column_letter + str(row)].value
value = ws[column_letter + str(row)].value
if value == 'false' or value == 'False':
value = False
if value == 'true' or value == 'True':
value = True
my_dict[ws[column_letter + str(FIRST_ROW)].value] = value
my_list.append(my_dict)
index = index + 1

data = json.dumps(my_list, sort_keys=False, indent=4, ensure_ascii=False)
with open('data.json', 'w', encoding='utf-8') as f:
with open(OUTPUTFILE, 'w', encoding='utf-8') as f:
f.write(data)
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
# MuPiBox_MusikVerwaltung
Musik Verwaltung Excel2Json für die MuPiBox (https://mupibox.de/)
Verwaltung der Medienbibliothek der MuPiBox (https://mupibox.de/) in einer Excel Tabelle

## Zielsetzung
Mit diesem Skript kann die Musikverwaltung für die MuPiBox in einer Excel Datei durchgeführt werden. Auf Basis der Excel Datei wird die für die MuPiBox notwendige data.json Datei generiert, welche dann nur noch auf die MuPiBox kopiert werden muss.
Mit den Python Skripten in diesem repo kann die Medienbibliothek der MuPiBox in einer Excel Tabelle verwaltet werden.

Das Skript `MuPiBox-MusikVerwaltung-json2xlsx.py` generiert auf Basis der `data.json` Datei der
MuPiBox eine Excel Tabelle, in der dann die Medienbibliothek verwaltet werden kann. Nachdem in der Tabelle
Einträge editiert, hinzugefügt oder gelöscht wurden, wird mit dem Skript `MuPiBox-MusikVerwaltung-xlsx2json.py`
aus der Excel Tabelle die aktualisierte `data.json` Datei generieren, die dann wieder auf die MuPiBox kopiert wird.

## Vorraussetzung
- Aktuelle Python Version installieren (https://www.python.org/)
- openpyxl installieren (Folgenden Befehl auf der Konsole eingeben: ```pip install openpyxl```)
- SSH Verbindungsdaten der MuPiBox siehe https://mupibox.de/anleitungen/einstellungen/schnellzugriff-passwoerter/)
- Aktivierter FTP oder Samba Server auf der MuPiBox, um Dateien zu transferieren (siehe http://mupibox/network.php > Services)


## Excel Dokument aus data.json generieren
- SSH Verbindung zur Mupibox aufbauen und die `data.json` in den File Exchange Ordner kopieren: ```cp /home/dietpi/.mupibox/Sonos-Kids-Controller-master/server/config/data.json /home/dietpi/MuPiBox/data.json```
- `data.json` via FTP oder Samba von der Mupibox auf den Rechner in den Ordner mit dem Converter Skripten kopieren
- Das Python Skript `MuPiBox-MusikVerwaltung-json2xlsx.py` ausführen (z.B. in VSCode im Terminal mit dem Befehl ```python .\MuPiBox-MusikVerwaltung-json2xlsx.py```)
- Die Medienbibliothek in der Excel Tabelle verwalten (Einträge hinzufügen, löschen, editieren).
- Anschließend die aktualisierte `data.json` Datei exportieren und auf die MuPiBox kopieren (siehe nächster Abschnitt)

## data.json aus dem Excel Dokument generieren
- Excel Dokument und Pythonskript im selben Ordner ablegen
- Musik für die MuPiBox im Excel Dokument verwalten und speichern
- Wenn Excel Datei umbenannt wird, muss der Dateiname hier im Skript geändert werden: https://github.com/Feuer-sturm/MuPiBox_MusikVerwaltung/blob/515d3d6e02c7477e89f033842d04a717e37a0b9b/MuPiBox-MusikVerwaltung-xlsx2json.py#L5
- Python Skript ausführen (z.B. in VSCode im Terminal mit dem Befehl ```py .\MuPiBox-MusikVerwaltung-xlsx2json.py```)
- data.json wird generiert
- data.json z.B. via FTP auf die Mupibox kopieren
- SSH Verbindung zur Mupibox aufbauen und die data.json an den korrekten Zielort kopieren: ```cp /home/dietpi/MuPiBox/data.json /home/dietpi/.mupibox/Sonos-Kids-Controller-master/server/config/data.json```
- In der Regel reicht es aus, auf der MuPiBox Oberfläche zwischen Musik, Hörbuch, Radio zu wechseln, so dass die neue data.json geladen wird. Notfalls die MuPiBox einmal neustarten
- Sicherstellen, dass das Excel Dokument und Pythonskript im selben Ordner liegen
- Wenn die Excel Datei umbenannt wurde, muss der Dateiname auch im Skript geändert werden (https://github.com/Feuer-sturm/MuPiBox_MusikVerwaltung/blob/515d3d6e02c7477e89f033842d04a717e37a0b9b/MuPiBox-MusikVerwaltung-xlsx2json.py#L5)
- Das Python Skript `MuPiBox-MusikVerwaltung-xlsx2json.py` ausführen (z.B. in VSCode im Terminal mit dem Befehl ```python .\MuPiBox-MusikVerwaltung-xlsx2json.py```)
- `data.json` wird generiert
- `data.json` via FTP oder Samba auf die Mupibox kopieren
- SSH Verbindung zur Mupibox aufbauen und die `data.json` an den korrekten Zielort kopieren: ```cp /home/dietpi/MuPiBox/data.json /home/dietpi/.mupibox/Sonos-Kids-Controller-master/server/config/data.json```
- Auf der MuPiBox Oberfläche zwischen Musik/Hörbuch/Radio wechseln, so dass die `data.json` neu geladen wird. Notfalls die MuPiBox einmal neustarten.
- Wenn ihr noch lokale Musik auf der Mupibox habt, dann müsst über die MuPiBox Admin Seite -> Reiter Admin -> Menü "Music database" das "Clean and update music database" noch einmal anstoßen, damit die lokale Musik wieder zur internen data.json hinzugefügt wird

## How to transfer files via FTP on a Mac
- open a terminal
- switch to the folder where `data.json` is stored (usually the root folder of this repo)
- run `ftp mupibox` and enter the credentials (see https://mupibox.de/anleitungen/einstellungen/schnellzugriff-passwoerter/)
- run `put data.json`
- The file is transferred to the File Exchange folder of the MuPiBox
- exit the ftp client with `quit`

## Änderungshistorie
v1.0 (2024-01-05)
- Initiale Version

v1.1 (2024-01-07)
- json2xlsx Converter hinzugefügt
File renamed without changes.
File renamed without changes.

0 comments on commit a988f7b

Please sign in to comment.