Make run.sh more robust
This commit is contained in:
parent
5706443217
commit
fa68762e0c
2 changed files with 9 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ __pycache__/
|
||||||
*.pyo
|
*.pyo
|
||||||
*.pyc
|
*.pyc
|
||||||
*.json
|
*.json
|
||||||
|
*.gz
|
||||||
|
|
8
run.sh
8
run.sh
|
@ -13,8 +13,10 @@ previous_file=""
|
||||||
while true; do
|
while true; do
|
||||||
# Get one shot of data
|
# Get one shot of data
|
||||||
data="$("$PYTHON" "$(dirname "$0")"/trainmap_backup.py)"
|
data="$("$PYTHON" "$(dirname "$0")"/trainmap_backup.py)"
|
||||||
|
if test $? -ne 0; then echo "Error: failed to fetch trainmap data" >&2; continue; fi
|
||||||
|
|
||||||
timestamp="$(printf '%s\n' "$data" | jq ".timestamp / 1000 | round")"
|
timestamp="$(printf '%s\n' "$data" | jq ".timestamp / 1000 | round")"
|
||||||
|
if test "$timestamp" = "" || test "$timestamp" -lt 1705410073 || test "$timestamp" -gt 4102441200; then echo "Error: timestamp '$timestamp' invalid" >&2; continue; fi
|
||||||
file="$(date +%Y-%m-%d --date "@$timestamp").json"
|
file="$(date +%Y-%m-%d --date "@$timestamp").json"
|
||||||
|
|
||||||
# Write the data to file
|
# Write the data to file
|
||||||
|
@ -23,8 +25,12 @@ while true; do
|
||||||
# At the start of a new day, archive the previous day's file
|
# At the start of a new day, archive the previous day's file
|
||||||
if test "$previous_file" == ""; then
|
if test "$previous_file" == ""; then
|
||||||
previous_file="$file"
|
previous_file="$file"
|
||||||
elif test "$file" != "$previous_file" && test "$file" != ""; then
|
elif test "$file" != "$previous_file"; then
|
||||||
|
if test -e "$previous_file.gz"; then
|
||||||
|
echo "Warning: $previous_file.gz already exists, not archiving" >&2
|
||||||
|
else
|
||||||
gzip --best "$previous_file"
|
gzip --best "$previous_file"
|
||||||
|
fi
|
||||||
previous_file="$file"
|
previous_file="$file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue