Skip to content

Instantly share code, notes, and snippets.

@Navdevl
Created May 8, 2018 14:01
Show Gist options
  • Select an option

  • Save Navdevl/61eb43c6e05aa92d9282920a14f03f62 to your computer and use it in GitHub Desktop.

Select an option

Save Navdevl/61eb43c6e05aa92d9282920a14f03f62 to your computer and use it in GitHub Desktop.
Todoist BitBar
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Todoist Today</bitbar.title>
# <bitbar.version>v1.0.0</bitbar.version>
# <bitbar.dependencies>python</bitbar.dependencies>
# <bitbar.author>Navdevl</bitbar.author>
import json
from todoist.api import TodoistAPI
from pprint import pprint
import StringIO
import datetime
api = TodoistAPI('APIKEY')
output = StringIO.StringIO()
api.sync()
output.write("*******\n")
output.write('---\n')
user = api.state['user']
output.write("Hey {0} \n".format(user['full_name']))
completed_items = user['completed_today']
output.write('---\n')
output.write('Today 😼 | color=red \n')
total_items_to_complete = 0
for project in api.state['projects']:
project_data = api.projects.get_data(project['id'])
if len(project_data['items']) == 0:
continue
for item in project_data['items']:
try:
due_date = datetime.datetime.strptime(item['due_date_utc'][:15], '%a %d %b %Y')
today = datetime.date.today()
today_string = today.strftime('%a %d %b %Y')
except:
continue
if (item['due_date_utc'] is None) or (item['due_date_utc'][:15] in today_string) or (today > due_date.date()):
output.write("{0}\n".format(item['content']))
total_items_to_complete += 1
output.write('---\n')
total_items = completed_items + total_items_to_complete
completed_percentage = completed_items / float(total_items)
output_string = output.getvalue()
if completed_percentage == 0:
emoji = "💔"
else:
emoji = "❤️"
output_string = output_string.replace("*******", emoji)
print(output_string)
print("---")
print("Completed Stats: {0}/{1}".format(completed_items, total_items))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment