From aa9bb2887c96c9725233500d5778ea00c072f2a7 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 5 Jul 2022 11:41:41 +0200 Subject: [PATCH] Improve tools --- wyk/helpers/add-intro.sh | 2 + wyk/helpers/fix-intro.pl | 61 +++++++++++++++++++++++++++ wyk/helpers/{intro => intro-template} | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 wyk/helpers/fix-intro.pl rename wyk/helpers/{intro => intro-template} (89%) diff --git a/wyk/helpers/add-intro.sh b/wyk/helpers/add-intro.sh index 2a0fa7f..cb12e8a 100755 --- a/wyk/helpers/add-intro.sh +++ b/wyk/helpers/add-intro.sh @@ -1,3 +1,5 @@ #!/bin/bash +./helpers/fix-intro.pl $1 + perl -pne 's/^{"cells":\[//' $1 | cat helpers/intro - | sponge $1 diff --git a/wyk/helpers/fix-intro.pl b/wyk/helpers/fix-intro.pl new file mode 100755 index 0000000..8493e5f --- /dev/null +++ b/wyk/helpers/fix-intro.pl @@ -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); diff --git a/wyk/helpers/intro b/wyk/helpers/intro-template similarity index 89% rename from wyk/helpers/intro rename to wyk/helpers/intro-template index 7d82176..9b9cafa 100644 --- a/wyk/helpers/intro +++ b/wyk/helpers/intro-template @@ -8,7 +8,7 @@ "![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n", "
\n", "

Modelowanie języka

\n", - "

11. Transformer [wykład]

\n", + "

NUMBER. TITLE [wykład]

\n", "

Filip Graliński (2022)

\n", "
\n", "\n",