Improve tools

This commit is contained in:
Filip Gralinski 2022-07-05 11:41:41 +02:00
parent 7c270a9360
commit aa9bb2887c
3 changed files with 64 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#!/bin/bash
./helpers/fix-intro.pl $1
perl -pne 's/^{"cells":\[//' $1 | cat helpers/intro - | sponge $1

61
wyk/helpers/fix-intro.pl Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/perl
use strict;
binmode(STDERR, ':utf8');
my $intro_file = 'helpers/intro';
my $intro_template = 'helpers/intro-template';
my $notebook_file = $ARGV[0];
my $number;
if (($number) = ($notebook_file =~ m{^(\d+)_})) {
} else {
die "????";
}
my $org_file = $notebook_file;
$org_file =~ s{\.ipynb}{\.org};
my $title = undef;
open(my $org_fh, '<', $org_file);
binmode($org_fh, ':utf8');
LOOP:
while (my $line=<$org_fh>) {
chomp $line;
if ($line =~ m{^\* (.*)}) {
$title = $1;
last LOOP;
} elsif ($line =~ /\S/) {
last LOOP;
}
}
if (not defined($title)) {
die '???? TITLE';
}
print STDERR "NUMBER: $number\n";
print STDERR "TITLE: $title\n";
my $intro = '';
open(my $intro_ih, '<', $intro_template);
binmode($intro_ih, ':utf8');
while(my $line=<$intro_ih>) {
$line =~ s{NUMBER}{$number};
$line =~ s{TITLE}{$title};
$intro .= $line;
}
close($intro_ih);
open(my $intro_oh, '>', $intro_file);
binmode($intro_oh, ':utf8');
print $intro_oh $intro;
close($intro_oh);

View File

@ -8,7 +8,7 @@
"![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n",
"<div class=\"alert alert-block alert-info\">\n",
"<h1> Modelowanie języka</h1>\n",
"<h2> 11. <i>Transformer</i> [wykład]</h2> \n",
"<h2> NUMBER. <i>TITLE</i> [wykład]</h2> \n",
"<h3> Filip Graliński (2022)</h3>\n",
"</div>\n",
"\n",