Fix missing .Mathematica dir from home install
[khome.git] / home / bin / today
CommitLineData
d746703e 1#! /bin/bash
4af9eedb
SK
2
3set -e
4
d746703e
SK
5DIR_DATA="$HOME/var/run/today"
6FILE_WEATHER="$DIR_DATA/weather"
7
8mkdir -p "$DIR_DATA"
9
4af9eedb
SK
10repeat() {
11 x="$1"
12 n="$2"
13 awk -v x="$x" -v n="$n" 'BEGIN {for (i=1; i<=n; i++) {printf x}}'
14}
15
16bar=$(repeat '-' '80')
17ts_fmt='+%A, %Y %B %d, %H:%M:%S'
18ts_lang='el_GR.UTF-8'
19timestamp_local=$(LANG="$ts_lang" date "$ts_fmt")
20timestamp_west=$( LANG="$ts_lang" TZ='US/Pacific' date "$ts_fmt")
21timestamp_pl=$( LANG="$ts_lang" TZ='Poland' date "$ts_fmt")
22timestamp_nz=$( LANG="$ts_lang" TZ='NZ' date "$ts_fmt")
23
24ip_addresses=$(
25 ip addr \
26 | awk '
27 /^[0-9]+:/ {
28 interface = $2
29 sub(":$", "", interface)
30 interfaces[++interface_count] = interface
31 }
32
33 /^ +inet +/ {
34 addr = $2
35 sub("/[0-9]+$", "", addr)
36 addrs[interface] = addr
37 }
38
39 END {
40 for (i=1; i<=interface_count; i++) {
41 interface = interfaces[i]
42 print interface, addrs[interface]
43 }
44 }' \
45 | column -t
46)
47
d746703e
SK
48weather_fetch() {
49 curl "http://wttr.in/${ZIP_CODE}?1" \
50 1> "$FILE_WEATHER" \
51 2> /dev/null
52}
53
e2aa4554
SK
54weather_file_age() {
55 echo $(( $(date +%s) - $(stat -c '%Y' "$FILE_WEATHER") ))
56}
57
d746703e 58weather_get_or_fetch() {
d746703e 59 weather_file_age_limit=$(( 3 * 60 * 60 ))
e2aa4554 60 if [[ ! -e $FILE_WEATHER || weather_file_age -ge $weather_file_age_limit ]]
d746703e
SK
61 then
62 weather_fetch
63 fi
64 cat "$FILE_WEATHER"
65}
4af9eedb 66
e2aa4554
SK
67weather="$(weather_get_or_fetch)"
68
4af9eedb
SK
69clear
70#LANG="$ts_lang" ncal -M $(date +%Y)
71LANG="$ts_lang" ncal -M
72echo "$bar"
73(
74 echo 'LOCAL' ',' "$timestamp_local"
75 echo 'Pacific' ',' "$timestamp_west"
76 echo 'Poland' ',' "$timestamp_pl"
77 echo 'New Zealand' ',' "$timestamp_nz"
78) \
79| column -ts,
80echo "$bar"
81echo "$ip_addresses"
82echo "$bar"
83echo ''
d746703e 84echo "Fetched on: $(stat -c %y $FILE_WEATHER)"
e2aa4554 85echo "$weather"
4af9eedb 86echo ''
This page took 0.078334 seconds and 4 git commands to generate.