From 204136670d471372de1d6812217b5be631f48467 Mon Sep 17 00:00:00 2001 From: Piotr Wilczynski Date: Sat, 10 Aug 2013 14:40:07 +0200 Subject: [PATCH] adds *@remind* --- README.md | 7 ++++++- topy/src/todolist_utils.py | 8 +++++++- utilities/create_reminder.py | 21 +++++++++++++++++++++ utilities/end_the_day.py | 6 ++---- utilities/remind.py | 22 ++++++++++++++++++++++ 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100755 utilities/create_reminder.py create mode 100644 utilities/remind.py diff --git a/README.md b/README.md index bb69d0e..ce611d5 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This is something that I use everyday and works as it is but I add things when I # Changelog # +- 2013-08-10 - added actions for **@remind** tag - 2013-08-10 - added actions for **@followup** tag - 2013-08-10 - added todify - iOS pythonista script that adds task tagged with *@today* to notification center - 2013-05-19 - minor improvement in how abbreviations in queries are expanded @@ -291,7 +292,7 @@ At the moment no tasks are removed from Onhold.todo. ### end_the_day -Joins several of other scripts. Launchd runs it for me at the and of the day. +Joins several of other scripts. Launchd runs it for me at the and of the day. ### reminders_to_topy ### @@ -300,6 +301,10 @@ some path must be adjusted in AppleScript *reminders_to_topy.applescript*. It allows to put items into Inbox with Siri on iOS (just put reminder in *Inbox* list and import it when on Mac or set this script in launchd). +### remind + +Adds items tagged with **@remind(YYYY-MM-DD)** to Reminders.app and changes tag to **@willremind(YYYY-MM-DD)**. + ### itopy, utopy, qtopy, todify ### Version of script to use in [Pythonista](http://omz-software.com/pythonista/) iOS app. Most of the source was merged to not clutter scripts list in app. Requires [seamless dropbox](https://github.com/bevesce/Seamless-Dropbox) diff --git a/topy/src/todolist_utils.py b/topy/src/todolist_utils.py index abcd50a..4149e8e 100644 --- a/topy/src/todolist_utils.py +++ b/topy/src/todolist_utils.py @@ -29,7 +29,9 @@ def custom_tag_regexp(tag): def add_tag_to_text(text, tag, param=None): if text[-1] != ' ': text += ' ' - text += "@" + tag + if not tag.startswith('@'): + tag = '@' + tag + text += tag if param: text += '({0})'.format(param) return text @@ -84,6 +86,10 @@ def remove_trailing_tags(line): return ' @'.join(sp[0:idx]) +def remove_tags(line): + return tag_pattern.sub('', line) + + def extract_content(typ, line): text = extract_text(typ, line) if typ in ('task', 'note'): diff --git a/utilities/create_reminder.py b/utilities/create_reminder.py new file mode 100755 index 0000000..3994a4e --- /dev/null +++ b/utilities/create_reminder.py @@ -0,0 +1,21 @@ +import subprocess + +applescript_template = """tell application \\"Reminders\\" + set r to make new reminder + set name of r to \\"{name}\\" + set body of r to \\"{body}\\" + set remind me date of r to date \\"{reminde_me_date}\\" +end tell""" + + +def create_reminder(name, body, reminde_me_date): + reminde_me_date = reminde_me_date.strftime('%d-%m-%Y %H:%M') + applescript = applescript_template.format( + name=name, + body=body, + reminde_me_date=reminde_me_date, + ) + cmd = 'echo "{0}" | osascript'.format(applescript) + subprocess.check_output( + cmd, shell=True + ) diff --git a/utilities/end_the_day.py b/utilities/end_the_day.py index 5b2d225..f76640a 100644 --- a/utilities/end_the_day.py +++ b/utilities/end_the_day.py @@ -3,12 +3,12 @@ import topy # from archive import archive from update_lists import update_daily, update_weekly, update_waiting, update_followups +from remind import set_reminders from tvcal import tvcal from log_to_day_one import log_to_day_one all_lists = topy.from_files(topy.lists.to_list()) inbox_file = open(inbox_path, 'a') -# archive_list = topy.from_file(archive_path) onhold_list = topy.from_file(onhold_path) log_to_day_one(all_lists.deep_copy()) @@ -18,10 +18,8 @@ pass update_weekly(onhold_list, inbox_file) update_waiting(onhold_list, inbox_file) -# inbox_file.close() update_daily(all_lists) -# archive(all_lists, archive_list) update_followups(all_lists) -# archive_list.to_file(archive_path) +set_reminders(all_lists) topy.save(all_lists) diff --git a/utilities/remind.py b/utilities/remind.py new file mode 100644 index 0000000..30fb538 --- /dev/null +++ b/utilities/remind.py @@ -0,0 +1,22 @@ +from datetime import datetime +from create_reminder import create_reminder +import topy + + +def set_reminders(todolist): + for item in todolist.filter('@remind +d'): + if item.has_tag('@remind'): + remind_date_str = item.get_tag_param('@remind') + remind_date = datetime.strptime(remind_date_str, '%Y-%m-%d %H:%M') + item.remove_tag('remind') + create_reminder( + item.title.text, + item.sub_tasks.as_plain_text(indent=False) if item.sub_tasks else '', + remind_date, + ) + item.tag('willremind', param=remind_date_str) + +if __name__ == '__main__': + all_lists = topy.from_files(topy.lists.to_list()) + set_reminders(all_lists) + topy.save(all_lists)