-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwine.sh
executable file
·44 lines (34 loc) · 1.34 KB
/
twine.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
#!/bin/bash
#
# flip phillips
# fall 2016
#
# read a twine's temperature sensor, upload to a wolfram data drop databin
#
WGET="/usr/local/bin/wget"
DROP="/usr/local/bin/drop_data.sh"
# sets EMAIL, PASSWORD, DATABIN, and TWINEID
if [[ -f ./twine.config ]]; then
source ./twine.config
elif [[ -f /usr/local/etc/twine.config ]]; then
source /usr/local/etc/twine.config
elif [[ -f /etc/twine.config ]]; then
source /etc/twine.config
else
echo "No configuration found."
exit -1
fi
: "${EMAIL?Need to set EMAIL non-empty}"
: "${PASSWORD?Need to set PASSWORD non-empty}"
: "${DATABIN:?Need to set DATABIN non-empty}"
: "${TWINEID:?Need to set TWINEID non-empty}"
LOGIN="email=$EMAIL&password=$PASSWORD"
$WGET -o /tmp/log.txt --quiet -O /tmp/temp.txt --keep-session-cookies --save-cookies /tmp/cookies.txt --no-check-certificate --post-data=${LOGIN} https://twine.cc/login
$WGET -o /tmp/log.txt --quiet -O /tmp/temp.txt --load-cookies /tmp/cookies.txt --no-check-certificate https://twine.cc/${TWINEID}/rt?cached=1
TEMP=`cat /tmp/temp.txt | awk -F"," '{print $7}' | awk -F"]" '{print $1}' | tr -d ' '`
TEMP=`bc <<< "scale=2; $TEMP/100"`
# these are obviously not necessary, but hesful for debugging
$DROP $DATABIN time `date "+%m%d%H%M%Y.%S"`
$DROP $DATABIN host `hostname`
$DROP $DATABIN temperature $TEMP
$DROP $DATABIN --send &> /tmp/twine.log