Created
October 12, 2020 14:48
-
-
Save tott/90815e8865f763884b726ee0f11d31fa to your computer and use it in GitHub Desktop.
Get Tasks currently assigned to you from Teamwork api and import to topydo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Get token from edit profile API & Mobile https://developer.teamwork.com/projects/apikey/key | |
# Get auth string by base64 encoding <token>:<randomstring> | |
# https://www.base64encode.org/ can be used to create such encoded string | |
token=<authstring> | |
authString="Authorization: Basic $token" | |
# Get user id from your profile url (/#/people/<userid>/tasks) | |
userId=<userid> | |
# Fill in your subdomain | |
baseUrl=https://xxx.teamwork.com/ | |
if [ -f /tmp/teamwork.csv ]; then | |
rm /tmp/teamwork.csv | |
fi | |
curl -s -H "$authString" $baseUrl/tasks.json?responsible-party-ids=$userId | | |
jq -r '."todo-items"[]|[(.id|tostring),."project-name",."project-id",.content]|@csv' > /tmp/teamwork.csv | |
# Adding teamwork tasks | |
while read -r line; do | |
id=$(echo $line | awk -F',' '{printf "%s", $1}' | tr -d '"') | |
project=$(echo $line | awk -F',' '{printf "%s", $2}' | tr -d '"' | tr -cd '[:alnum:]._-') | |
projectid=$(echo $line | awk -F',' '{printf "%s", $3}' | tr -d '"') | |
content=$(echo $line | awk -F',' '{printf "%s", $4}' | tr -d '"') | |
project="+$project" | |
exists=$(topydo ls -F "%r" -x teamwork:$id|cut -d"|" -f 2) | |
if [ -z "$exists" ]; then | |
topydo add "$content" $project @teamwork teamwork:$id url:$baseUrl/#/projects/$projectid/tasks/$id | |
fi | |
done < /tmp/teamwork.csv | |
# Removing tasks deleted or completed in teamwork | |
for teamworkid in `topydo ls -F "%r" -x @teamwork | grep -oP "(?<=teamwork:)([0-9]+)"`; do | |
hit=0 | |
while read -r line; do | |
id=$(echo $line | awk -F',' '{printf "%s", $1}' | tr -d '"') | |
if [ "$id" == "$teamworkid" ]; then | |
hit=1 | |
fi | |
done < /tmp/teamwork.csv | |
if [ $hit -eq 0 ]; then | |
topydo do -x -e "teamwork:$teamworkid" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment