fix(user/calcGalTick):Specify timezone as UTC
[BK-2020-03.git] / user / mw_create_summary_months.sh
CommitLineData
d02b8fe0
SBS
1#!/usr/bin/env bash
2# Desc: Prints mediawiki code for a summary of months of a year on the bk4 wiki.
3# Usage: /bin/bash mw_create_summary_months.sh [int year]
4# Input: arg1: year
5# Example: /bin/bash mw_create_summary_months.sh [int year] > output.txt
6# Version: 0.0.1
7
8yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
9die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
10must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
11main() {
12 yyyy="$1";
13
14 # Check input
15 if [[ $# -ne 1 ]]; then die "FATAL:Invalid arg count:$#"; fi;
16 ## Strip leading zeroes (because August/octal)
17 yyyy="$((10#${yyyy}))";
18 ## Check year
19 re="[0-9]+";
20 if [[ ! $yyyy =~ $re ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
21 if [[ ! $yyyy -ge 1582 ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
22
23 # Calc working vars
24 ## Years
25 yyyy_prev="$((yyyy - 1))";
26 yyyy_next="$((yyyy + 1))";
27
28 # Form and print header
29 printf "{{bk journal header}}\n";
30 printf "A summary of monthly journals of [[%d]]. " "$yyyy";
31 printf "Preceded by [[Summary of months of %d]]. " "$yyyy_prev";
32 printf "Followed by [[Summary of months of %d]]. " "$yyyy_next";
33 printf "\n\n";
34
35 # Form and print body
36 for (( mm=1; mm <= 12; mm++)); do
37 printf "=[[%4d-%02d]]=" "$yyyy" "$mm";
38 printf "\n";
39 printf "{{:%4d-%02d}}" "$yyyy" "$mm";
40 printf "\n";
41
42 done;
43 printf "\n\n";
44
45 # Form and print footer
46 printf "{{bk journal footer}}\n";
47 s1="[[Category:Monthly summaries by year]]"
48 printf "%s\n" "$s1";
49 printf "\n";
50
51}; # main program
52
53main "$@";
54
55# Author: Steven Baltakatei Sandoval
56#+License: GPLv3+