Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Tasks currently assigned to you from Teamwork api and import to topydo
#!/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
You can’t perform that action at this time.