feat(user/mw_create...):Update mediawiki journal create scripts
[BK-2020-03.git] / user / mw_create_month_journal_range.sh
CommitLineData
61078d97 1#!/usr/bin/env bash
338bd5c9
SBS
2# Desc: Wrapper for creating monthly journal page generation script
3# Input: arg1: path mw_create_month_journal.sh
4# arg2: year start
5# arg3: year end
6# Example: mw_create_month_journal_range.sh ./mw_create_month_journal.sh 2030 2040
61078d97 7# Depends: BK-2020-03: mw_create_month_journal.sh
338bd5c9 8# Version: 1.0.0
61078d97
SBS
9
10# plumbing
338bd5c9
SBS
11path_cmj="$1"; # eg "$HOME/scripts/mw_create_month_journal.sh"
12year_start="$2"; # eg 2030
13year_end="$3"; # eg 2040
61078d97
SBS
14dir_out="./wikicode/";
15
16yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
17die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
18must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
19check_depends() {
20 # check location of `mw_create_month_journal.sh`
21 if [[ ! -f "$path_cmj" ]]; then die "FATAL:Not found:$path_cmj"; fi;
22};
23check_plumbing() {
24 if [[ ! -d "$dir_out" ]]; then
25 yell "STATUS:Creating missing dir_out:$dir_out";
26 mkdir -p "$dir_out"; fi;
27};
28main() {
29 check_depends;
30 check_plumbing;
31
32 while read -r year; do
33 while read -r month; do
34 monthp="$(printf "%2d" "$month")";
35 # Define and execute create monthly journal command
36 cmj_args+=("$year");
37 cmj_args+=("$month");
38
39 # Define output file path
40 path_out="$dir_out"/"$(printf "%d-%02d" "$year" "$month")";
41
42 # Execute
43 "$path_cmj" "${cmj_args[@]}" > "$path_out";
44
45 unset cmj_args;
46 done < <(seq 1 12); # each month
47 done < <(seq "$year_start" "$year_end"); # each year
48};
49
50main "$@";
51
52# Author: Steven Baltakatei Sandoval
53# License: GPlv3+