def date_to_key(self, date): diff = get_today() - date if diff.days < 0: return 'the future' elif diff.days == 0: return 'last restore' else: return '%d days ago' % diff.days
def offset(self): if self.date is None: return -TaskDate.FUTURE elif self.date == TaskDate.FUTURE: return TaskDate.FUTURE elif self.date == TaskDate.SOON: return 3 return (self.date - get_today()).days
def __init__(self, offset_days=None, date=None): if date: self.date = date elif offset_days is None: self.date = None elif offset_days is TaskDate.FUTURE: self.date = TaskDate.FUTURE elif offset_days is TaskDate.SOON: self.date = TaskDate.SOON else: self.date = get_today() + make_timedelta(offset_days)
def sync(self): swap = self.path + '~' backup = self.path + '.backup-%d' % now().weekday() with open(swap, 'w') as s: data = { 'tasks': self.tasks, 'events': self.events, 'day': get_today(), } s.write(dumps(data)) file_api.update(data) if os.path.exists(self.path): os.rename(self.path, backup) os.rename(swap, self.path)
def markup(self): """Returns same text as __str__, but with markup to hide extraneous text. This enables the combobox to match the strings.""" if self.date is None: # emulate a horizontal dash return '<span strikethrough="true" size="700">No Date</span>' elif self.date == TaskDate.FUTURE: return '<span size="1">In the </span>Future' elif self.date == TaskDate.SOON: return '<span size="1">Sometime </span>Soon' x = self.hname() if x == 'In 1 Week': return '%s/%s - <span size="1">In </span>1 W<span size="1">ee</span>k' % (self.date.month, self.date.day) elif x == 'Today': return '%s/%s - Today' % (self.date.month, self.date.day) elif x == 'Tomorrow': return '%s/%s - Tomorrow' % (self.date.month, self.date.day) if self.date.year != get_today().year: return '%s/%s/%s' % (self.date.month, self.date.day, self.date.year) return '%s/%s - %s<span size="0">%s</span>' % (self.date.month, self.date.day, x[:3], x[3:])
parse_class = Task last_updated = None if text[0] != '### Tasks ###': raise Exception for line in text: if line.startswith('### Recurring Events ###'): parse_class = WeeklyRecurringEvent parse_out = events elif line.startswith('#'): if 'Last updated:' in line: try: last_updated = datetime.datetime.strptime(line[16:], "%a %b %d %H:%M:%S %Y") except ValueError, ve: print ve continue elif line: parse_out.append(parse_class.from_human(line)) if not tasks or not last_updated: raise Exception return { 'tasks': tasks, 'events': events, 'day': get_today(), 'last_taskhat_update': last_updated, } def watch(callback): """Starts thread that will call back on file update""" _io_watcher.add_callback(callback)