mirror of
https://gitlab.com/parroquia-san-leandro/cancionero-web.git
synced 2025-07-11 07:46:59 +02:00
songbook generator
This commit is contained in:
parent
c084ca2d89
commit
6535d4d7dd
5 changed files with 158 additions and 4 deletions
40
src/create_songbook.py
Normal file
40
src/create_songbook.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import latex_scanner
|
||||
from os.path import join
|
||||
from django.template import Engine, Context
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def generate_songbook(song_loader, song_numbers, out_file, dj_engine):
|
||||
# Build the list of songs
|
||||
song_list = []
|
||||
for n in song_numbers:
|
||||
found = None
|
||||
for song in song_loader.songs:
|
||||
if song.number == n:
|
||||
found = song
|
||||
break
|
||||
if not found:
|
||||
raise Exception("Could not find song with number " + str(n))
|
||||
song_list.append(found)
|
||||
# Export to html
|
||||
context = Context({'songs': song_list})
|
||||
with open(out_file, 'w') as f:
|
||||
f.write(dj_engine.get_template("songbook.html").render(context))
|
||||
|
||||
|
||||
def create_argparser():
|
||||
parser = latex_scanner.create_argparser()
|
||||
parser.add_argument("--songs", required=True, nargs='+', type=int, help="A list of song numbers to include.")
|
||||
parser.add_argument("--output-file", required=False, nargs=1, default=["misa.html"],
|
||||
help="The file where the result should be placed, relative to --output-dir.")
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = create_argparser().parse_args()
|
||||
loader = latex_scanner.SongLoader(args.latex[0], args.audios[0])
|
||||
if args.other_latex:
|
||||
loader.scan_others(args.other_latex[0], args.other_index[0])
|
||||
settings.configure(USE_TZ=False, USE_I18N=False)
|
||||
e = Engine(dirs=["res/templates/"])
|
||||
generate_songbook(loader, args.songs, join(args.output_dir[0], args.output_file[0]), e)
|
Loading…
Add table
Add a link
Reference in a new issue