Browse Source

create basic index of songs

automate
mxmehl 6 months ago
parent
commit
ba1463d85a
Signed by: mxmehl GPG Key ID: 2704E4AB371E2E92
  1. 1
      .gitignore
  2. 5
      Makefile
  3. 1
      requirements.txt
  4. 40
      scripts/create-index.py

1
.gitignore

@ -1,2 +1,3 @@
.~lock*
build/
venv/

5
Makefile

@ -24,8 +24,11 @@ build/Songs/%.pdf : src/Songs/%.odt
build/Extra/%.pdf : src/Extra/%.odt
@soffice --headless "-env:UserInstallation=file:///tmp/LibreOffice_Conversion" --convert-to pdf:writer_pdf_Export --outdir build/Extra/ "$<"
index:
@python3 scripts/create-index.py
bundle:
@pdfunite build/Extra/Cover+Intro.pdf build/Songs/* build/Extra/Akkorde.pdf build/Songbook.pdf
@pdfunite build/Extra/Cover+Intro.pdf build/Extra/Index.pdf build/Songs/* build/Extra/Akkorde.pdf build/Songbook.pdf
.PHONY: clean
clean: ## remove all build artifacts

1
requirements.txt

@ -0,0 +1 @@
fpdf2

40
scripts/create-index.py

@ -0,0 +1,40 @@
from fpdf import FPDF
import glob
import os
import re
def wline(text):
pdf.cell(txt=text, ln=1)
pdf = FPDF(format = "A5")
pdf.add_page()
pdf.set_margin(10)
# Print Title
pdf.set_font('courier', size=16, style="BU")
pdf.cell(0, 6, 'Songbook-Index', ln=1, align='C')
# Print index of Songs
pdf.set_font('courier', size=8)
for file_name in sorted(glob.iglob('build/Songs/*.pdf')):
# converts file name to e.g. D03_Hotel_California
file_name = os.path.splitext(os.path.basename(file_name))[0]
# = Hotel California
song_name = file_name.split("_",1)[1].replace("_", " ")
# = D
song_cat = file_name[0]
# = 3
song_no = int(re.sub(r'^0', '', file_name[1:3]))
# Treat new category starts differently
if song_no == 0:
pdf.ln(1)
wline(f"{song_cat}. {song_name}")
else:
wline(f" {song_no}. {song_name}")
pdf.ln(1)
wline("Akkorde")
pdf.output("build/Extra/Index.pdf")
Loading…
Cancel
Save