Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
TaskPaper Worklfows for Regex Matching Past and Today’s Date
-
I really like how the TaskPaper 3 Mac app is aware of dates and allows for relative date queries, such as the following shared by @macdrifter for finding all available items with start dates on today or in the past.
Available @search(@today or @start <[d] today)
I found myself wanting this on iOS, so I've cobbled together some python and regex to achieve it in Editorial.
Here is an ingredient Editorial workflow that generates a regex to match all lines containing @start(yyyy-mm-dd) tags for today's date and all dates before today (stored in two different workflow variables respectively). The python scripts have an option up top to change "start" to some other tag like "due" to match due date tags.
http://www.editorial-workflows.com/workflow/5867115714183168/xGNRsW6uGhA
Here are two workflows that use these variables.
This first workflow shows a popover of all tasks tagged with today or past start dates. Tapping on an item takes you to that item in the document and highlights the task.
http://www.editorial-workflows.com/workflow/5865285923897344/HL42MJmOIiI
The second folds all lines except those with start tags today or in the past (similar to @macdrifter's Available search above). It also leaves project titles unfolded so you have those for reference. This one could be improved by not showing projects headers that do not contain available tasks and also showing descendants of available tasks like indented notes or subtasks on the following line(s), but I haven't yet been able to figure those things out. I'll keep trying, but maybe someone else could work that out.
http://www.editorial-workflows.com/workflow/5818118995705856/onvBSXAqBoY
Note: These workflows only work for dates between 2000-01-01 and 2029-12-31. Hopefully, scheduling 15 years out is not a significant need.
-
I am a bit lost in the explanation and workflow but here is some Python code that might help...
import datetime tag = 'start' today = datetime.date.today() data = ''' No tag goes nowhere @start() empty tag goes nowhere An old task @start(1970-02-13) goes in the past Today's task goes in the present @start({:%Y-%m-%d}) A future task@start( 2059-11-20 )goes in the future A slash-based date @start(2001/01/01) goes nowhere '''.format(today) print(data) def get_past_present_and_future(data=data, tag='start'): at_tag = '@{}('.format(tag) past, present, future = [], [], [] for line in data.splitlines(): task_date = line.partition(at_tag)[2].partition(')')[0].strip() if task_date and task_date.count('-') == 2: task_date = datetime.datetime.strptime(task_date, '%Y-%m-%d').date() if task_date < today: past.append(line) elif task_date == today: present.append(line) else: future.append(line) return tuple(past), tuple(present), tuple(future) print(get_past_present_and_future(data, 'start'))
-
Sorry if it was not clear. The first workflow stores the regex for matching past and today start tags in a variable. The other two workflows use this variable by calling it from the first workflow in a sub-workflow step. Does that clear things up?
What specifically is your Python supposed to help with?
-
My point was that perhaps you were overthinking this use case. Regex and the entire first script are not required to effectively solve the problem at hand. This is because your data is so "well formed" that a single line of Python can isolate the date as a string (
task_date = line.partition(at_tag)[2].partition(')')[0].strip()
) and another line (task_date = datetime.datetime.strptime(task_date, '%Y-%m-%d').date()
) can convert that string into adatetime.date
that can be trivially compared todatetime.date.today()
to determine if this task is in the past, present, or future.My code above shows that your second and third scripts could find past and present tasks merely by looking for
task-date <= today
. No regex required, no first script, and no artificial 15 year limit.EDIT: As I think about it more, given that your dates are already in year-month-day sort order, you do not even need to convert them to dates... You can just leave them as strings and do string compares with today's date as a string (
'{:%Y-%m-%d}'.format(datetime.date.today())
). -
Ah, I see. Yes, I am probably doing this the hard way. It didn't occur to me to do it your way, but it is good to know your approach is possible and easier. Thank you for sharing. It is very helpful.