-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwu-pws.sh
executable file
·109 lines (83 loc) · 4.35 KB
/
wu-pws.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
## JH: v1.0 - Weather Underground to pwsweather.com script test
WORKINGDIR=/home/ABC123
# Wunderground API key
# Register for a free Stratus plan here: https://www.wunderground.com/weather/api
WUAPI={your weather underground API key - no braces}
# Wunderground PWS to pull weather from
# Navigate to your preferred weather station on Weather Underground and pull the pws:XXXXXXXXXX from the URL
# ex. https://www.wunderground.com/cgi-bin/findweather/getForecast?query=pws:KFLLAKEW61&MR=1
# ex. WUPWS would be the query value - "pws:KFLLAKEW61"
#WUPWS="pws:KFLLAKEW53"
WUPWS={"your weather underground station identifier - no braces - yes quotes"}
#PWS station ID - sign up and create a station at pwsweather.com
PWSID={your pwsweather.com station ID}
#PWS password - password for pwsweather.com
PWSPASS={your pwsweather.com password}
#============================================================
#=
#= NOT NECESSARY TO CHANGE ANY LINES BELOW
#=
#============================================================
# Construct & Execute Weather Underground API call
WUJSON=http://api.wunderground.com/api/$WUAPI/conditions/q/$WUPWS\.json
echo "Grabbing JSON using the following URL: $WUJSON"
echo ""
wget -O $WORKINGDIR/wu.json $WUJSON
# ALL json extractions below REQUIRE the jq cmd line tool - on Ubuntu 'apt-get install jq'
#
# extract observation time and convert to UTC
# jq .current_observation.observation_epoch wu.json |tr -d '"'
# TZ=UTC date -d @1459187921 +'%Y-%m-%d+%H:%M:%S'|sed 's/:/%3A/g'
PWSDATEUTC=$(TZ=UTC date -d @$(jq .current_observation.observation_epoch $WORKINGDIR/wu.json |tr -d '"') +'%Y-%m-%d+%H:%M:%S'|sed 's/:/%3A/g')
echo "PWSDATEUTC=$PWSDATEUTC"
# extract winddir
PWSWINDDIR=$(jq .current_observation.wind_degrees $WORKINGDIR/wu.json |tr -d '"')
echo "PWSWINDDIR=$PWSWINDDIR"
# extract windspeed
PWSWINDSPEEDMPH=$(jq .current_observation.wind_mph $WORKINGDIR/wu.json |tr -d '"')
echo "PWSWINDSPEEDMPH=$PWSWINDSPEEDMPH"
# extract windgustmph
PWSWINDGUSTMPH=$(jq .current_observation.wind_gust_mph $WORKINGDIR/wu.json |tr -d '"')
echo "PWSWINDGUSTMPH=$PWSWINDGUSTMPH"
# extract tempf
PWSTEMPF=$(jq .current_observation.temp_f $WORKINGDIR/wu.json |tr -d '"')
echo "PWSTEMPF=$PWSTEMPF"
# extract hourly rainin - Hourly rain in inches
PWSRAININ=$(jq .current_observation.precip_1hr_in $WORKINGDIR/wu.json |tr -d '"')
echo "PWSRAININ=$PWSRAININ"
# extract daily rainin - Daily rain in inches
PWSDAILYRAININ=$(jq .current_observation.precip_today_in $WORKINGDIR/wu.json |tr -d '"')
echo "PWSDAILYRAININ=$PWSDAILYRAININ"
# extract baromin - Barometric pressure in inches
PWSBAROMIN=$(jq .current_observation.pressure_in $WORKINGDIR/wu.json |tr -d '"')
echo "PWSBAROMIN=$PWSBAROMIN"
# extract dewptf - Dew point in degrees f
PWSDEWPTF=$(jq .current_observation.dewpoint_f $WORKINGDIR/wu.json |tr -d '"')
echo "PWSDEWPTF=$PWSDEWPTF"
# extract humidity - in percent
PWSHUMIDITY=$(jq .current_observation.relative_humidity $WORKINGDIR/wu.json |tr -d '"' |tr -d '%')
echo "PWSHUMIDITY=$PWSHUMIDITY"
# extract solarradiation
PWSSOLARRADIATION=$(jq .current_observation.solarradiation $WORKINGDIR/wu.json |tr -d '"'|tr -d '-')
echo "PWSSOLARRADIATION=$PWSSOLARRADIATION"
# extract UV
PWSUV=$(jq .current_observation.UV $WORKINGDIR/wu.json |tr -d '"')
echo "PWSUV=$PWSUV"
# construct PWS weather POST data string
PWSPOST="ID=$PWSID&PASSWORD=$PWSPASS&dateutc=$PWSDATEUTC&winddir=$PWSWINDDIR&windspeedmph=$PWSWINDSPEEDMPH&windgustmph=$PWSWINDGUSTMPH&tempf=$PWSTEMPF&rainin=$PWSRAININ&dailyrainin=$PWSDAILYRAININ&baromin=$PWSBAROMIN&dewptf=$PWSDEWPTF&humidity=$PWSHUMIDITY&solarradiation=$PWSSOLARRADIATION&UV=$PWSUV&softwaretype=wu_pws_ver1.0&action=updateraw"
#echo $PWSPOST
RESULT=$(wget -O /dev/null --post-data=$PWSPOST http://www.pwsweather.com/pwsupdate/pwsupdate.php)
echo wget -O /dev/null --post-data=$PWSPOST http://www.pwsweather.com/pwsupdate/pwsupdate.php
# retains 10 backup cycles for debugging
rm $WORKINGDIR/wu.json.10
mv $WORKINGDIR/wu.json.9 $WORKINGDIR/wu.json.10
mv $WORKINGDIR/wu.json.8 $WORKINGDIR/wu.json.9
mv $WORKINGDIR/wu.json.7 $WORKINGDIR/wu.json.8
mv $WORKINGDIR/wu.json.6 $WORKINGDIR/wu.json.7
mv $WORKINGDIR/wu.json.5 $WORKINGDIR/wu.json.6
mv $WORKINGDIR/wu.json.4 $WORKINGDIR/wu.json.5
mv $WORKINGDIR/wu.json.3 $WORKINGDIR/wu.json.4
mv $WORKINGDIR/wu.json.2 $WORKINGDIR/wu.json.3
mv $WORKINGDIR/wu.json.1 $WORKINGDIR/wu.json.2
mv $WORKINGDIR/wu.json $WORKINGDIR/wu.json.1