-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-completed-tasks.sh
executable file
·75 lines (60 loc) · 1.37 KB
/
get-completed-tasks.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
#!/usr/bin/env bash
usage() {
cat << EOF
Usage: $(basename $0) -t <token> [-b <backup_file> | -v]
Options:
-t <token> Your Todoist API token
-b <backup_file> Location of a backup file to append deleted tasks to (optional)
-v Show verbose output (optional)
EOF
exit
}
join_by() {
local IFS="$1";
shift;
echo "$*";
}
TOKEN=
BACKUP_FILE=
VERBOSE=
while [[ "${1}" != "" ]]; do
case "${1}" in
-t ) TOKEN="${2}";;
-b ) BACKUP_FILE="${2}";;
-v ) VERBOSE=true;;
esac
shift
done
if [ -z "${TOKEN}" ]; then
usage
fi
if ! command -v uuid 2>&1 > /dev/null; then
echo "Error: uuid command required"
exit 1
fi
IDS=X
OFFSET=0
BATCH_SIZE=200
if [ -n "${BACKUP_FILE}" ]; then
echo '[' > ${BACKUP_FILE}
fi
until [ -z "${IDS}" ]; do
TASKS=$(curl -s https://api.todoist.com/sync/v9/completed/get_all \
-H "Authorization: Bearer ${TOKEN}" \
-d offset=${OFFSET} \
-d limit=${BATCH_SIZE} | jq -r ".items ")
if [ "${TASKS}" == "[]" ]; then
break
fi
if [ -n "${BACKUP_FILE}" ]; then
if [ "${OFFSET}" != "0" ]; then
echo "," >> ${BACKUP_FILE}
fi
echo "${TASKS:1:${#TASKS}-2}" >> ${BACKUP_FILE}
fi
OFFSET=$((${OFFSET} + ${BATCH_SIZE}))
sleep 2
done
if [ -n "${BACKUP_FILE}" ]; then
echo ']' >> ${BACKUP_FILE}
fi