Skip to content

Commit

Permalink
Add option to skip current event after certain time (#40)
Browse files Browse the repository at this point in the history
Authored-by: Jorge Pérez <[email protected]>
  • Loading branch information
Ktl-XV authored May 28, 2020
1 parent 3e2de92 commit a033499
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Run `sudo pip3 install python-bidi google-api-python-client google-auth-httplib2
max number of events to query Google's API for each of your calendars. Increase this number if you have lot of events in your google calendar
--today, -d print only today events
--no-event-text TEXT text to display when there are no events
--hide-event-after MINUTES
minutes to show events after they start before showing the next event. If not specified, the current event will be shown until it ends
```

### Filter displayed calendars
Expand Down
13 changes: 11 additions & 2 deletions i3_agenda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
default="No events",
metavar="TEXT",
help='text to display when there are no events')
parser.add_argument('--hide-event-after',
type=int,
default=-1,
help='minutes to show events after they start before showing the next event. If not specified, the current event will be shown until it ends')

class Event():
def __init__(self, summary: str, is_allday: bool, unix_time: float, end_time: float):
Expand Down Expand Up @@ -94,7 +98,7 @@ def main():
args.today)
save_cache(events)

closest = get_closest(events)
closest = get_closest(events, args.hide_event_after)
if closest is None:
print(args.no_event_text)
return
Expand Down Expand Up @@ -165,7 +169,7 @@ def get_event_time(full_time: str) -> float:
datetime.datetime.strptime(full_time, format).astimezone().timetuple())


def get_closest(events: List[Event]) -> Optional[Event]:
def get_closest(events: List[Event], hide_event_after: int) -> Optional[Event]:
closest = None
for event in events:
# Don't show all day events
Expand All @@ -176,6 +180,11 @@ def get_closest(events: List[Event]) -> Optional[Event]:
if event.end_time < time.time():
continue

if hide_event_after > -1:
# If the event started more than hide_event_after ago
if event.unix_time + 60 * hide_event_after < time.time():
continue

if closest is None or event.unix_time < closest.unix_time:
closest = event

Expand Down

0 comments on commit a033499

Please sign in to comment.