Skip to content

Instantly share code, notes, and snippets.

@galvez
Created February 20, 2016 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvez/c5566b8f9bd26e88af2e to your computer and use it in GitHub Desktop.
Save galvez/c5566b8f9bd26e88af2e to your computer and use it in GitHub Desktop.
Add pomodoros to a task by typing spaces
# coding=utf-8
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from fabric.api import local
import time
import re
import datetime
import code
class TodayEventHandler(FileSystemEventHandler):
def on_modified(self, event):
if not re.search('Today.txt$', event.src_path):
return
groups = {'top': []}
top_group = False
all_lines = []
with open(event.src_path) as tf:
for line in tf:
if line.lstrip() == '' and top_group:
top_group = False
if top_group:
groups['top'].append(line)
elif line.strip() == '⚡':
top_group = True
all_lines.append('⚡\n')
else:
all_lines.append(line)
for i, task in enumerate(groups['top']):
if re.search('\w \n', task):
groups['top'][i] = groups['top'][i].replace(' \n', ' ·\n')
elif re.search('\w \n', task):
groups['top'][i] = groups['top'][i].replace(' \n', ' 🍅\n')
if task.endswith('· \n'):
groups['top'][i] = '%s 🍅\n' % task[:-5]
elif task.endswith('🍅 \n'):
groups['top'][i] = '%s🍅\n' % task[:-2]
top_group_index = all_lines.index('⚡\n')
all_lines[top_group_index+1:top_group_index+1] = groups['top']
with open(event.src_path, 'w') as tfw:
tfw.write(''.join(all_lines))
def watch():
event_handler = TodayEventHandler()
observer = Observer()
observer.schedule(event_handler, '.')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment