-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatumhom
executable file
·53 lines (42 loc) · 1.83 KB
/
datumhom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Prints date, time, weather for airports. Only reads weather after "often" secs have passed. Needs "metar", and notice "where" to set the ICAO code of location.
# Can use with gltext screensaver (/usr/share/applications/screensavers/gltext.desktop):
# Exec=gltext -root -front -program ~/bin/datumhom
# Metar seems to break regularly. This might help:
export METARURL="https://tgftp.nws.noaa.gov/data/observations/metar/stations/"
# Where to collect from? --> instead do metar set eggd
where="eggd" #Bristol
# How often should we update the weather (in sec)?
often=300
#Echo the date and time
#date +'%y.%m.%e %a, %H:%M'
date +'%y.%m.%d %a, %H:%M'
# Do we have the dir?
if [ ! -d ~/.datumhom ]; then
mkdir ~/.datumhom
fi
# Do we have the file?
if [ -e ~/.datumhom/hom.txt ]; then
# The file was refreshed at:
refreshedat=`ls -l --time-style\=+%s ~/.datumhom/hom.txt | awk '{ print$6 }' `
# Time now is, then subtract $often:
shouldhaverefreshed=`date +%s`
let shouldhaverefreshed=$shouldhaverefreshed-$often
# If file is too old, refresh:
if [ $refreshedat -lt $shouldhaverefreshed ]; then
if [ ! -f "/etc/arch-release" ]; then
metar -d $where|awk '{ if ($1=="Temperature") print($3 "C"); if ($2=="speed") printf("%.0f" "km/h; ",$4*1.852) }' > ~/.datumhom/hom.txt
else
metar get|awk '{ if ($1=="Temperature:") print(substr($4,2) "C"); if ($1=="Wind:") printf("%.0f" "km/h; ",$8*1.852) }' > ~/.datumhom/hom.txt
fi
fi
else
# If file doesn't exist, refresh:
if [ ! -f "/etc/arch-release" ]; then
metar -d $where|awk '{ if ($1=="Temperature") print($3 "C"); if ($2=="speed") printf("%.0f" "km/h; ",$4*1.852) }' > ~/.datumhom/hom.txt
else
metar get|awk '{ if ($1=="Temperature:") print(substr($4,2) "C"); if ($1=="Wind:") printf("%.0f" "km/h; ",$8*1.852) }' > ~/.datumhom/hom.txt
fi
fi
#Print the file
cat ~/.datumhom/hom.txt