Das Songbook
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.7 KiB

"""Create an index of Songbook files, both as PDF and Markdown"""
import argparse
import glob
import os
import re
from fpdf import FPDF
from shutil import copyfile
parser = argparse.ArgumentParser(description='Create songbook index')
parser.add_argument("-t", "--type", dest="type",
choices=["ay", "az"], default="az",
help="Define whether to build A-Z or A-Y")
args = parser.parse_args()
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')
pdf.ln(4)
# Prepare and open songbook.md
copyfile("templates/songbook.md", "build/songbook.md")
f = open("build/songbook.md", "a")
# Print index of Songs
if args.type == "az":
SELECTION = "[A-Z]"
OUTPUT = "Index.pdf"
else:
SELECTION = "[A-Y]"
OUTPUT = "Index_A-Y.pdf"
for file_name in sorted(glob.iglob(f'build/Songs/{SELECTION}*.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.set_font('courier', size=8, style="B")
pdf.cell(txt=f"{song_cat}. {song_name}", ln=1)
f.write(f"1. {song_name}\n")
else:
pdf.set_font('courier', size=8)
pdf.cell(txt=f" {song_no}. {song_name}", ln=1)
f.write(f" 1. {song_name}\n")
pdf.cell(txt="**Akkorde**", ln=1, markdown=True)
pdf.output(f"build/Extra/{OUTPUT}")