Skip to content

Instantly share code, notes, and snippets.

@guiniol
Last active August 15, 2017 07:56
Show Gist options
  • Save guiniol/1fa308ef1679a04bbc84985de0c70add to your computer and use it in GitHub Desktop.
Save guiniol/1fa308ef1679a04bbc84985de0c70add to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import datetime as dt
import khal.settings as settings
import khal.khalendar as khalendar
import khal.cli as cli
import khal.controllers as controllers
conf = settings.get_config()
env = {"calendars": conf['calendars']}
agenda_format = conf['view']['agenda_event_format']
day_format = conf['view']['agenda_day_format']
locale = conf['locale']
notstarted = False
collection = cli.build_collection(conf, None)
start = dt.datetime.now()
end = start + dt.timedelta(days=2)
start_local = locale['local_timezone'].localize(start)
end_local = locale['local_timezone'].localize(end)
start = start_local.replace(tzinfo=None)
end = end_local.replace(tzinfo=None)
events = sorted(sorted(collection.get_localized(start_local, end_local)) +
sorted(collection.get_floating(start, end)))
for event in events:
if event.allday:
continue
now = dt.datetime.now()
start = event.start.replace(tzinfo=None)
if start.date() == now.date():
print('Today, {time} → {summary}'.format(
time=start.time().strftime('%H:%M'),
summary=event.summary.strip()))
if start < now:
print('#bb88dd')
else:
try:
alarm = sorted(event.alarms, key=lambda x: x[0])[-1][0]
if start + alarm < now:
print('#ff0090')
elif start + 3 * alarm < now:
print('#ffba68')
else:
print('#80ff00')
except:
print('#80ff00')
elif start.date() == now.date() + dt.timedelta(days=1):
print('Tomorrow, {time} → {summary}'.format(
time=start.time().strftime('%H:%M'),
summary=event.summary.strip()))
else:
print('{date}, {time} → {summary}'.format(
date=start.date().strftime('%Y/%m/%d'),
time=start.time().strftime('%H:%M'),
summary=event.summary.strip()))
sys.exit(0)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment