Skip to content

Instantly share code, notes, and snippets.

@kiselev-nikolay
Created December 9, 2020 07:42
Show Gist options
  • Save kiselev-nikolay/6edcea339521aa2c89990a39d6bdfd40 to your computer and use it in GitHub Desktop.
Save kiselev-nikolay/6edcea339521aa2c89990a39d6bdfd40 to your computer and use it in GitHub Desktop.
Todoist terminal intergration
token="YOUR_TODOIST_TOKEN_HERE"
nowt=$(expr $(date +%s) / 14400)
test -f /tmp/todoistTasks$nowt.json \
|| curl --silent -q https://api.todoist.com/sync/v8/sync \
-d token=$token \
-d sync_token='*' \
-d resource_types='["items"]' > /tmp/todoistTasks$nowt.json
printf "\033[1;32mTasks need to be done:\033[0m\n"
cat /tmp/todoistTasks$nowt.json | python3 -c "
import sys, json, datetime
data = json.load(sys.stdin)
todos = []
red, orange, blue = '\033[0;31m', '\033[0;33m', '\033[0;36m'
reset = '\033[m'
for t in data['items']:
content = t['content'][:60]
if len(t['content']) > 60:
content = content + '...'
priority = ('X' * t['priority']).ljust(4, '-')
if priority == 'XXXX':
priority = red + priority + reset
if priority == 'XXX-':
priority = orange + priority + reset
if priority == 'XX--':
priority = blue + priority + reset
if t['due'] is None:
continue
due_datetime = datetime.datetime.fromisoformat(t['due']['date'])
due_day = due_datetime.strftime('%Y-%m-%d')
now_datetime = datetime.datetime.now()
now_day = now_datetime.strftime('%Y-%m-%d')
if now_day == due_day:
todos.append(' '.join((' ', ' ', priority, content)))
elif now_datetime > due_datetime:
todos.append(' '.join((' ', red + 'o' + reset, priority, content)))
todos.sort()
print(*todos, sep='\n')
"
printf "\n\033[0;30mhttps://todoist.com/app/#/today\033[0m\n"
@kiselev-nikolay
Copy link
Author

kiselev-nikolay commented Dec 9, 2020

To use it:

  1. Move file to bin sudo mv todoist.sh /usr/bin/todoist.sh

  2. Change access rules sudo chmod 511 /usr/bin/todoist.sh

  3. Add following to bashrc or zshrc file

alias todos="/usr/bin/todoist.sh"
alias updatetodos="find /tmp -name 'todoistTask*.json' 2> /dev/null | xargs rm && todos"

;todos;

@kiselev-nikolay
Copy link
Author

You will get:
Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment