update(user/bkdatev):Add Helsinki, Finland
[BK-2020-03.git] / user / mw_create_year_journal.sh
... / ...
CommitLineData
1#!/usr/bin/env bash
2# Desc: Prints mediawiki code for a journal year in the bk4 wiki.
3# Usage: /bin/bash mw_create_year_journal.sh [int year]
4# Input: arg1: year
5# Example: /bin/bash mw_create_year_journal.sh 2023 > output.txt
6# Version: 0.0.1
7
8yyyy="$1";
9
10yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
11die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
12must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
13
14# Check input
15## Check arg count
16if [[ $# -ne 1 ]]; then die "FATAL:Invalid arg count:$#"; fi;
17## Strip leading zeros
18yyyy="$((10#${yyyy}))";
19
20## Check year
21re="[0-9]+";
22if [[ ! $yyyy =~ $re ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
23if [[ ! $yyyy -ge 1582 ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
24
25# Calc working vars
26## Years
27yyyy_prev="$((yyyy - 1))";
28yyyy_next="$((yyyy + 1))";
29
30# Form and print header
31printf "{{bk journal header year}}\n";
32printf "[[Journal]] for the year [[%d]]. " "$yyyy";
33printf "Preceded by [[%d]]. " "$yyyy_prev";
34printf "Followed by [[%d]]. " "$yyyy_next";
35printf "\n\n";
36
37printf "==Events==\n";
38printf "\n";
39
40# Form and print body
41for (( mm=1; mm <= 12; mm++ )); do
42 printf "==[[%4d-%02d]]==\n" "$yyyy" "$mm";
43done;
44printf "\n";
45
46# Form and print footer
47s1="==References==";
48s2="<references>";
49s3="</references>";
50printf "%s\n%s\n%s\n" "$s1" "$s2" "$s3";
51printf "\n";
52
53printf "==See Also==\n";
54printf "\n";
55
56printf "==Ext. Links==\n";
57printf "\n";
58
59printf "{{bk journal footer year}}\n";
60
61s1="[[Category:Journals by year]]";
62printf "%s\n" "$s1";
63printf "\n";