Editorial Workflows

Set Reminders

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Scans taskpaper for tasks/projects with tags (@reminder, @due) and sets/updates alerts in iOS reminders. In 'Editorial' lists.
Alerts could be relative (+hh:mm) [also just (+h:) or (+:mm) also (+:75)] or at set time (hh:mm). If it is past reminder hour script assumes alert supposed to be set for tomorrow.
v 1.0
ToDo:
- handle @done tag - skip or mark existing reminder as completed
- Maybe @due should set reminder due date & @reminder set alert (now they both set alert and date interchangeable)
- split regex - regex works fine for now but will get unreadable with time - split into few sequential tests
- handle different Reminders calendars - now it is using calendar ID fixed in code
- handle calendar dates not only time? (I never really use long term reminders)
- sync both directions?

Shared by: chew-z

Comments: Comment Feed (RSS)

zarazum — 06 Sep 2016
Does not work — indentation problem on line 17/
anonymous — 19 Apr 2018

+ Add Comment

Workflow Preview
Document Text ?
Folded Text
  • Include
  • Replace with:
Run Python Script ?
Source Code
#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 get_reminders(line):
	# 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()
				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)
				# due is tomorrow
				if due < now:
					due += timedelta(days=1)
		return todo, due
	return None, None
			
def set_reminders(todo, due):
	# sets/updates iOS reminders
	# '33B23FFD-02A9-4C3F-934B-BAB33C985EA4'
	# print calendar.identifier to get id
	# id = get_id('Editorial')
	c = reminders.get_calendar('33B23FFD-02A9-4C3F-934B-BAB33C985EA4')
	# print c.title
	rs = reminders.get_reminders(c, False)
	for r in rs:
		# print r.title, todo
		if r.title == todo:
			# print 'updating', todo
			r.due_date = due
			a = reminders.Alarm()
			a.date = due
			r.alarms = [a]
			return r.save()
	else:
		# print 'creating', todo
		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
		# find todo and set reminder.completed
	else:
		todo, due = get_reminders(line)
		if todo is not None:
			# print todo, due
			set_reminders(todo, due)
	
action_out = action_in
workflow.set_output(action_out)