mirror of
				https://gitlab.com/parroquia-san-leandro/cancionero-web.git
				synced 2025-10-30 20:58:39 +01:00 
			
		
		
		
	songbook generator
This commit is contained in:
		
					parent
					
						
							
								c084ca2d89
							
						
					
				
			
			
				commit
				
					
						6535d4d7dd
					
				
			
		
					 5 changed files with 158 additions and 4 deletions
				
			
		
							
								
								
									
										55
									
								
								res/static/misa/editor.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								res/static/misa/editor.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,55 @@ | |||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|   <meta charset="UTF-8"> | ||||
|   <title>Editor</title> | ||||
|   <meta name="viewport" content="width=device-width, initial-scale=1"/> | ||||
|   <style> | ||||
| ul { | ||||
|   list-style: none; | ||||
| } | ||||
| ul li:before { | ||||
|   content: '- \0000a0'; | ||||
|   font-weight: bold; | ||||
| } | ||||
|   </style> | ||||
|   <script> | ||||
| var inputs = [] | ||||
| 
 | ||||
| function changed() { | ||||
|   var lastNum = document.getElementById("lastNum") | ||||
|   if (lastNum.value) { | ||||
|     inputs.push(lastNum) | ||||
|     lastNum.name = "song[]" | ||||
|     lastNum.onchange = | ||||
|     lastNum.removeAttribute("onchange") | ||||
|     lastNum.removeAttribute("onkeyup") | ||||
|     lastNum.removeAttribute("id") | ||||
| 
 | ||||
| 		var newNum = document.createElement("INPUT") | ||||
| 		newNum.type = "number" | ||||
| 		newNum.id = "lastNum" | ||||
| 		newNum.max = 500 | ||||
| 		newNum.min = 1 | ||||
| 		newNum.onchange = newNum.onkeyup = () => changed() | ||||
| 		var li = document.createElement("LI") | ||||
| 		li.appendChild(newNum) | ||||
| 		document.getElementById("list").appendChild(li) | ||||
|   } | ||||
| } | ||||
|   </script> | ||||
| </head> | ||||
| <body> | ||||
| <header> | ||||
|   <h1>Editor</h1> | ||||
| </header> | ||||
| <main> | ||||
|   <form action="generar.php" method="post"> | ||||
|     <ul id="list"> | ||||
|       <li><input id="lastNum" type="number" max="500" min="1" onkeyup="changed()" onchange="changed()"></li> | ||||
|     </ul> | ||||
|     <button type="submit">Enviar</button> | ||||
|   </form> | ||||
| </main> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										21
									
								
								res/static/misa/generar.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								res/static/misa/generar.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| <?php | ||||
| 
 | ||||
| $song_list = ""; | ||||
| foreach ($_POST["song"] as $i) | ||||
| 	if ($i) $song_list .= "$i "; | ||||
| 
 | ||||
| $cmd  = "python3 ../../cancionero-web-python/src/latex_scanner.py"; | ||||
| $cmd .= " --latex ../../cancionero-web-python/latex/cancionero.tex"; | ||||
| $cmd .= " --other-latex ../../cancionero-web-python/latex/canciones/"; | ||||
| $cmd .= " --other-index 400"; | ||||
| $cmd .= " --output-dir ."; | ||||
| $cmd .= " --output-file index.html"; | ||||
| $cmd .= " --songs $song_list"; | ||||
| exec($cmd, $output, $return_code); | ||||
| 
 | ||||
| foreach ($output as $line) echo "$line\n"; | ||||
| 
 | ||||
| if ($return_code) | ||||
| 	echo "The return code was $return_code\n"; | ||||
| 
 | ||||
| ?>
 | ||||
							
								
								
									
										38
									
								
								res/templates/songbook.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								res/templates/songbook.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|   {% include "head.html" with path="." only %} | ||||
|   <link rel="stylesheet" type="text/css" href="song.css"/> | ||||
|   <link rel="stylesheet" type="text/css" href="index.css"/> | ||||
|   <script async src="song.js"></script> | ||||
| </head> | ||||
| <body> | ||||
| {% include "header.html" with path="." %} | ||||
| <main> | ||||
|   <h2>Índice</h2> | ||||
|   <ol class="songs"> | ||||
|     {% for song in songs %} | ||||
|     <a href="#{{ song.number }}"><li> | ||||
|       <span class="number">{{ song.number }}.</span> | ||||
|       {{ song.name }} | ||||
|     </li></a> | ||||
|     {% endfor %} | ||||
|   </ol> | ||||
|   {% for song in songs %} | ||||
|   <div class="song" id="wholeSongDiv"> | ||||
|     <h2 id="{{ song.number }}">{{ song.number }}. {{ song.name }}</h2> | ||||
|     <div id="songLyrics"> | ||||
|       {% for verse in song.verses %} | ||||
|       <div class="{{ verse.kind }}"> | ||||
|         {% for line in verse.lines %} | ||||
|         {{ line }}<br/> | ||||
|         {% endfor %} | ||||
|       </div> | ||||
|       {% endfor %} | ||||
|     </div> | ||||
|   </div> | ||||
|   {% endfor %} | ||||
| </main> | ||||
| {% include "footer.html" %} | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										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) | ||||
|  | @ -278,21 +278,21 @@ class SongLoader: | |||
|         self.print_index(join(output_dir, "index.html"), dj_engine) | ||||
| 
 | ||||
| 
 | ||||
| def parse_args(): | ||||
| def create_argparser(): | ||||
|     parser = argparse.ArgumentParser() | ||||
|     parser.add_argument("--latex", required=True, nargs=1, help="The main LaTeX file. It may include other documents") | ||||
|     parser.add_argument("--other-latex", required=False, nargs=1, default=[None], | ||||
|                         help="A folder with songs, those not referenced in the main file will be included at the end.") | ||||
|     parser.add_argument("--other-index", required=False, nargs=1, default=["400"], | ||||
|     parser.add_argument("--other-index", required=False, nargs=1, type=int, default=[400], | ||||
|                         help="The first song number for songs outside the main songbook.") | ||||
|     parser.add_argument("--audios", required=False, nargs=1, default=[None], | ||||
|                         help="The folder containing the audio files.") | ||||
|     parser.add_argument("--output-dir", required=False, nargs=1, default=["public"]) | ||||
|     return parser.parse_args() | ||||
|     return parser | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     args = parse_args() | ||||
|     args = create_argparser().parse_args() | ||||
|     loader = SongLoader(args.latex[0], args.audios[0]) | ||||
|     if args.other_latex: | ||||
|         loader.scan_others(args.other_latex[0], int(args.other_index[0])) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue