aboutsummaryrefslogtreecommitdiff
path: root/data/scripts/log-sync
blob: e810f6e0939da12c0472e22d586b215ae58d55b6 (plain) (blame)
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
#!/bin/bash
source "${BASH_ARGV0%/*}"/common.sh
RAW_DATA_PATH=""

enmac="$(getaddr "$(getiface "net/e")")"
wlmac="$(getaddr "$(getiface "net/w")")"

get_logs()
{
	find "${XDG_CACHE_HOME:-$HOME/.cache}/Watcher/$1" -type f -exec basename -a '{}' + \
		| grep -oE "$2"
}

# shellcheck disable=SC2031,SC2030
if [[ $1 == "weekly" ]]; then
	watcher -ws 2> /dev/null >&2

	get_logs Analysis '[0-9]+-[0-9]+' \
		| while IFS=- read -r week year; do
			! communicate "/whack/a/mole" user/weekly "$wlmac" "$enmac" "$year" "$week" --silent --fail || continue

			echo "Uploading log: Week $week, $year" >&2
			communicate "/puss/in/boots" user/weekly "$wlmac" "$enmac" "$year" "$week" \
				-# --data-urlencode "data@$RAW_DATA_PATH/Analysis/W$week-$year.csv"
		done
else
	get_logs daily_data '[0-9]{4}(-[0-9]{2}){2}' \
		| while IFS=- read -r year month day; do
			! [[ $(date --rfc-3339=date) == "$year-$month-$day" ]] || continue
			! communicate "/whack/a/mole" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" --silent --fail || continue

			echo "Uploading log: $year-$month-$day" >&2
			communicate "/puss/in/boots" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" \
				-# --data-urlencode "data@$RAW_DATA_PATH/daily_data/$year-$month-$day.csv"
		done
fi