minor corrections and distribution of the generated file

This commit is contained in:
Carlos Galindo 2021-10-01 21:50:08 +02:00
parent 6535d4d7dd
commit 890c2397e3
6 changed files with 85 additions and 31 deletions

37
canciones-updater.php Normal file
View file

@ -0,0 +1,37 @@
<?php
$song_list = "";
foreach ($_POST["song"] as $i)
if ($i) $song_list .= "$i ";
$cmd = "python3 /opt/cancionero-web-python/src/create_songbook.py";
$cmd .= " --latex /opt/cancionero-web-python/latex/cancionero.tex";
$cmd .= " --other-latex /opt/cancionero-web-python/latex/canciones/";
$cmd .= " --other-index 400";
$cmd .= " --output-dir /srv/http/canciones-updater/canciones/";
$cmd .= " --output-file result.html";
$cmd .= " --songs $song_list";
echo "<pre>";
passthru("$cmd 2>&1", $return_code);
echo "</pre>";
if ($return_code) {
http_response_code(500);
echo "An error occurred!<br/>See the data below<br/>";
echo "The return code was $return_code<br/>";
echo "Command: <pre>$cmd</pre>";
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script>
document.location.replace("https://canciones.sanleandro-obispo.net/misa/update_index.php")
</script>
</head>
<body>
You can see the result <a href="https://canciones.sanleandro-obispo.net/misa/update_index.php">here</a>.
</body>
</html>

View file

@ -21,7 +21,6 @@ function changed() {
if (lastNum.value) { if (lastNum.value) {
inputs.push(lastNum) inputs.push(lastNum)
lastNum.name = "song[]" lastNum.name = "song[]"
lastNum.onchange =
lastNum.removeAttribute("onchange") lastNum.removeAttribute("onchange")
lastNum.removeAttribute("onkeyup") lastNum.removeAttribute("onkeyup")
lastNum.removeAttribute("id") lastNum.removeAttribute("id")
@ -44,12 +43,15 @@ function changed() {
<h1>Editor</h1> <h1>Editor</h1>
</header> </header>
<main> <main>
<h2>Números de las canciones</h2>
<form action="generar.php" method="post"> <form action="generar.php" method="post">
<ul id="list"> <ul id="list">
<li><input id="lastNum" type="number" max="500" min="1" onkeyup="changed()" onchange="changed()"></li> <li><input id="lastNum" type="number" max="500" min="1" onkeyup="changed()" onchange="changed()"></li>
</ul> </ul>
<button type="submit">Enviar</button> <button type="submit">Enviar</button>
</form> </form>
<h2>Índice</h2>
<iframe src="/" height="400px" width="100%"></iframe>
</main> </main>
</body> </body>
</html> </html>

View file

@ -1,21 +0,0 @@
<?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";
?>

View file

@ -0,0 +1,24 @@
<?php
$ch = curl_init("https://csgj.pw/canciones/result.html");
$fp = fopen("index.html", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script>
setTimeout(() => document.location.replace("./"), 100);
</script>
</head>
<body>
You can see the result <a href="./">here</a>.
</body>
</html>

View file

@ -2,14 +2,15 @@ import latex_scanner
from os.path import join from os.path import join
from django.template import Engine, Context from django.template import Engine, Context
from django.conf import settings from django.conf import settings
import pickle
def generate_songbook(song_loader, song_numbers, out_file, dj_engine): def generate_songbook(songs, song_numbers, out_file, dj_engine):
# Build the list of songs # Build the list of songs
song_list = [] song_list = []
for n in song_numbers: for n in song_numbers:
found = None found = None
for song in song_loader.songs: for song in songs:
if song.number == n: if song.number == n:
found = song found = song
break break
@ -32,9 +33,19 @@ def create_argparser():
if __name__ == '__main__': if __name__ == '__main__':
args = create_argparser().parse_args() args = create_argparser().parse_args()
loader = latex_scanner.SongLoader(args.latex[0], args.audios[0]) try:
with open("songs.dat", "rb") as f:
songs = pickle.load(f)
except:
loader = latex_scanner.SongLoader(args.latex[0])
if args.other_latex: if args.other_latex:
loader.scan_others(args.other_latex[0], args.other_index[0]) loader.scan_others(args.other_latex[0], args.other_index[0])
songs = loader.songs
try:
with open("songs.dat", "wb") as f:
pickle.dump(songs, f)
except:
pass
settings.configure(USE_TZ=False, USE_I18N=False) settings.configure(USE_TZ=False, USE_I18N=False)
e = Engine(dirs=["res/templates/"]) e = Engine(dirs=["res/templates/"])
generate_songbook(loader, args.songs, join(args.output_dir[0], args.output_file[0]), e) generate_songbook(songs, args.songs, join(args.output_dir[0], args.output_file[0]), e)

View file

@ -35,11 +35,12 @@ def extra_put(extra, index, the_type, data=None):
class SongLoader: class SongLoader:
def __init__(self, latex_file, audio_dir): def __init__(self, latex_file, audio_dir=None):
self.index = 1 self.index = 1
self.category = None self.category = None
self.categories = [] self.categories = []
self.songs = [] self.songs = []
if audio_dir:
self.audio_dir = audio_dir self.audio_dir = audio_dir
self.scan(latex_file) self.scan(latex_file)