forked from empierre/domoticz_linky-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domoticz_linky.sh
executable file
·48 lines (43 loc) · 1 KB
/
domoticz_linky.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
#!/bin/sh
set -au
set -e
SCRIPT="$0"
BASE_DIR=$(dirname "${SCRIPT}")
export BASE_DIR
CFG_FILE="domoticz_linky.cfg"
LOG_FILE="domoticz_linky.log"
MONTH=0
if [ $# -eq 1 ]
then
MODE="monthly"
MONTH="$1"
else
MODE="daily"
fi
echo "${MODE} mode" >> "${BASE_DIR}"/"${LOG_FILE}"
update_db () {
if [ "$1" -eq 0 ]
then
PY_SCRIPT="linky_json.py"
else
PY_SCRIPT="linky_month.py"
fi
PY_SCRIPT="${BASE_DIR}"/"${PY_SCRIPT}"
"${PY_SCRIPT}" $1 -o "${BASE_DIR}" >> "${BASE_DIR}"/"${LOG_FILE}" 2>&1
if [ $? -eq 0 ]; then
BASE_DIR="${BASE_DIR}" /usr/bin/nodejs "${BASE_DIR}"/domoticz_linky.js "${DOMOTICZ_ID}" > "${BASE_DIR}"/req.sql
cat "${BASE_DIR}"/req.sql | /usr/bin/sqlite3 "${HOME}"/domoticz/domoticz.db
fi
}
# check configuration file
if [ -f "${BASE_DIR}"/"${CFG_FILE}" ]
then
. "${BASE_DIR}"/"${CFG_FILE}"
export LINKY_USERNAME
export LINKY_PASSWORD
export DOMOTICZ_ID
update_db "${MONTH}"
else
echo "Config file is missing ["${BASE_DIR}"/"${CFG_FILE}"]"
exit 1
fi