Skip to content

Instantly share code, notes, and snippets.

@var1ableX
Last active November 25, 2018 20:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save var1ableX/72972f77010bcfe3dc98f88ce6ee8212 to your computer and use it in GitHub Desktop.
Save var1ableX/72972f77010bcfe3dc98f88ce6ee8212 to your computer and use it in GitHub Desktop.
Taskpaper Reminders In Editorial
#coding: utf-8
import re
import editor
import dialogs
import datetime
import workflow
import reminders
from datetime import datetime, timedelta
from dateutil import parser
now = datetime.now()
def get_id(cal_name):
# get ID for Reminders list
all_calendars = reminders.get_all_calendars()
for calendar in all_calendars:
if calendar.title == cal_name:
#print (calendar.identifier)
return calendar.identifier
def print_reminders():
id = get_id('Editorial')
c = reminders.get_calendar(id)
todo = reminders.get_reminders(c, completed=False)
print ('TODO List')
print ('=========')
for r in todo:
print '[ ] ' + r.title
done = reminders.get_reminders(c, completed=True)
print ('DONE')
print ('====')
for r in done:
print ('[x] ') + r.title
def set_complete(todo):
id = get_id('Taskpaper')
c = reminders.get_calendar(id)
todos = reminders.get_reminders(c, completed=False)
for r in todos:
if r.title == todo:
r.completed = True
r.save()
#print(r.title, todo)
def get_reminders(line):
due = None
# get reminders from taskpaper
for todo, s_time in re.findall(r'\-?\s?(.*)(?:\s@reminder|\s@due)\((.*)\)', line):
#print todo, s_time
for t_pp, t_hh, t_mm in re.findall(r'(\+{0,1})(\d{0,2}):(\d{0,2})', s_time):
#print (t_pp, t_hh, t_mm)
if t_pp:
# '+' notation
due = datetime.now()
#print (due)
if t_hh:
due += timedelta(hours=int(t_hh))
if t_mm:
due += timedelta(minutes=int(t_mm))
else:
due = parser.parse(t_hh+':'+t_mm, fuzzy=True)
#print(due)
# due is tomorrow
if due < now:
due += timedelta(days=1)
if due and todo:
return todo, due
else:
return None, None
return None, None
def check_exists(rs, todo):
for r in rs:
#print r.title, todo
if r.title == todo:
return r
return None
def set_reminders(todo, due):
# sets/updates iOS reminders
# '33B23FFD-02A9-4C3F-934B-BAB33C985EA4'
# print calendar.identifier to get id
id = get_id('Taskpaper')
#print(id)
#c = reminders.get_calendar('33B23FFD-02A9-4C3F-934B-BAB33C985EA4')
c = reminders.get_calendar(id)
#print (c.title)
rs = reminders.get_reminders(c, False)
r = check_exists(rs, todo)
if r:
r.due_date = due
a = reminders.Alarm()
a.date = due
r.alarms = [a]
return r.save()
else:
r = reminders.Reminder(c)
r.title = todo
r.due_date = due
a = reminders.Alarm()
a.date = due
r.alarms = [a]
return r.save()
action_in = workflow.get_input()
for line in action_in.split('\n'):
if '@done' in line:
#print ('@done:', line)
todo, due = get_reminders(line)
set_complete(todo)
# find todo and set reminder.completed
else:
todo, due = get_reminders(line)
if todo is not None:
#print (todo, due)
set_reminders(todo, due)
#print_reminders()
action_out = action_in
workflow.set_output(action_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment