feat(user/mw_create...):Update mediawiki journal create scripts
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 25 Apr 2023 10:17:34 +0000 (10:17 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 25 Apr 2023 10:17:34 +0000 (10:17 +0000)
user/mw_create_month_journal.sh
user/mw_create_month_journal_range.sh
user/mw_create_year_journal_range.sh [new file with mode: 0644]

index 9ed0206d159a21ee43d66a065d647de438c2949b..b540fa9294251e0252f685bb6ba9ae77ad6d0ab3 100755 (executable)
@@ -4,7 +4,7 @@
 # Input: arg1: year
 #        arg2: month
 # Example: /bin/bash mw_create_month_journal.sh 2023 03 > output.txt
-# Version: 0.0.1
+# Version: 0.1.0
 
 yyyy="$1";
 mm="$2";
@@ -60,6 +60,7 @@ else
 fi;
 
 # Form and print header
+printf "{{bk journal header month}}\n";
 printf "Journal for [[%d]]-%02d. " "$yyyy" "$mm";
 printf "Preceded by [[%d-%02d]]. " "$yyyy_prev" "$mm_prev";
 printf "Followed by [[%d-%02d]]. " "$yyyy_next" "$mm_next";
@@ -101,6 +102,8 @@ printf "\n";
 printf "==Ext. Links==\n";
 printf "\n";
 
+printf "{{bk journal footer month}}\n";
+
 s1="[[Category:Journals by month]]";
 printf "%s\n" "$s1";
 printf "\n";
index f2846b59b1f50cb74383b9e3561a1449809e2a56..068987b575db64cab50304dd6821a023233af990 100644 (file)
@@ -1,13 +1,16 @@
 #!/usr/bin/env bash
+# Desc: Wrapper for creating monthly journal page generation script
+# Input: arg1: path mw_create_month_journal.sh
+#        arg2: year start
+#        arg3: year end
+# Example: mw_create_month_journal_range.sh ./mw_create_month_journal.sh 2030 2040
 # Depends: BK-2020-03: mw_create_month_journal.sh
-# Version: 0.0.1
-
-# update each run
-path_cmj="$HOME/git-OC/BK-2020-03..bkexdev/user/mw_create_month_journal.sh";
-year_start="1582";
-year_end="2100";
+# Version: 1.0.0
 
 # plumbing
+path_cmj="$1"; # eg "$HOME/scripts/mw_create_month_journal.sh"
+year_start="$2"; # eg 2030
+year_end="$3"; # eg 2040
 dir_out="./wikicode/";
 
 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
diff --git a/user/mw_create_year_journal_range.sh b/user/mw_create_year_journal_range.sh
new file mode 100644 (file)
index 0000000..63694ec
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Desc: Wrapper for creating yearly journal page generation script
+# Input: arg1: path mw_create_year_journal.sh
+#        arg2: year start
+#        arg3: year end
+# Example: mw_create_year_journal_range.sh ./mw_create_year_journal.sh 2030 2040
+# Depends: BK-2020-03: mw_create_year_journal.sh
+# Version: 0.0.1
+
+# plumbing
+path_cyj="$1"; # eg "$HOME/scripts/mw_create_year_journal.sh"
+year_start="$2"; # eg 2030
+year_end="$3"; # eg 2040
+dir_out="./wikicode/";
+
+yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
+die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
+must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
+check_depends() {
+    # check location of `mw_create_year_journal.sh`
+    if [[ ! -f "$path_cyj" ]]; then die "FATAL:Not found:$path_cyj"; fi;
+};
+check_plumbing() {
+    if [[ ! -d "$dir_out" ]]; then
+        yell "STATUS:Creating missing dir_out:$dir_out";
+        mkdir -p "$dir_out"; fi;
+};
+main() {
+    check_depends;
+    check_plumbing;
+
+    while read -r year; do
+        cyj_args+=("$year");
+        
+        # Define output file path
+        path_out="$dir_out"/"$(printf "%d" "$year")";
+        
+        # Execute
+        "$path_cyj" "${cyj_args[@]}" > "$path_out";
+        
+        unset cyj_args;
+    done < <(seq "$year_start" "$year_end"); # each year
+};
+
+main "$@";
+
+# Author: Steven Baltakatei Sandoval
+# License: GPlv3+