Skip to content

Commit

Permalink
FIX: improve substantially
Browse files Browse the repository at this point in the history
  • Loading branch information
jklymak committed Apr 19, 2020
1 parent c13dfbe commit 49b9a79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions gcalcli/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ def get_argument_parser():
calw.add_argument('weeks', type=int, default=1, nargs='?')

free = sub.add_parser(
'free', parents=[details_parser, output_parser, cal_query_parser],
'free', parents=[details_parser, output_parser, start_end_parser],
help='get free',
description='Get free timeslots in week.')
free.add_argument('weeks', type=int, default=1, nargs='?')
# free.add_argument('weeks', type=int, default=1, nargs='?')

sub.add_parser(
'calm', parents=[details_parser, output_parser, cal_query_parser],
Expand Down
5 changes: 2 additions & 3 deletions gcalcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ def main():
)

elif parsed_args.command == 'free':
print(parsed_args)
gcal.FreeQuery(start=parsed_args.start)

gcal.FreeQuery(start=parsed_args.start,
end=parsed_args.end)

elif parsed_args.command == 'calm':
gcal.CalQuery(parsed_args.command, start_text=parsed_args.start)
Expand Down
37 changes: 28 additions & 9 deletions gcalcli/gcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ def ListAllCalendars(self):
def _display_free(self, start, end, search=None,
year_date=False):
event_list = self._search_for_events(start, end, search)

day = start.replace(hour=0, minute=0, second=0, microsecond=0)
dayst = start.replace(hour=9, minute=0, second=0, microsecond=0)
nextst = dayst
Expand All @@ -1166,28 +1167,47 @@ def _display_free(self, start, end, search=None,
self.printer.msg(f'\nAvailability {dayst.strftime("%b %d")} - {end.strftime("%b %d")} \n', 'yellow')
self.printer.msg('---------------------------- \n\n', 'yellow')
for event in event_list:

while event['s'] > dayend:
self.printer.msg(prefix, 'green')
self.printer.msg(f" {nextst.strftime('%H:%M')} to {dayend.strftime('%H:%M')}\n", )
self.printer.msg(f" {nextst.strftime('%H:%M')} to ")
self.printer.msg(f"{dayend.strftime('%H:%M')}\n")
dayst = dayst + timedelta(days=1)
dayend = dayend + timedelta(days=1)
nextst = dayst
print_prefix = True
prefix = dayst.strftime('\n%a %b %d')
if event['s'] >= nextst:
if event['s'] > nextst:

self.printer.msg(prefix, 'green')
self.printer.msg(f" {nextst.strftime('%H:%M')} to {event['s'].strftime('%H:%M')}\n")
self.printer.msg(f" {nextst.strftime('%H:%M')} to ")
self.printer.msg(f"{event['s'].strftime('%H:%M')}\n")
nextst = event['e']
prefix = ' '
if (event['s'] <= nextst) and (event['e'] < dayend):
nextst = event['e']

# last event:
if event['e'] < dayend:
print(prefix + f" {nextst.strftime('%H:%M')} to {dayend.strftime('%H:%M')}")
self.printer.msg(prefix, 'green')
self.printer.msg(f" {nextst.strftime('%H:%M')} to ")
self.printer.msg(f"{event['s'].strftime('%H:%M')}\n")

# any trailing days with no events:
dayst = dayst + timedelta(days=1)
dayend = dayend + timedelta(days=1)
while dayst < end:
prefix = dayst.strftime('\n%a %b %d')
self.printer.msg(prefix, 'green')
self.printer.msg(f" {dayst.strftime('%H:%M')} to {dayend.strftime('%H:%M')}\n", )
dayst = dayst + timedelta(days=1)
dayend = dayend + timedelta(days=1)



def _display_queried_events(self, start, end, search=None,
year_date=False):
event_list = self._search_for_events(start, end, search)
print('agenda', len(event_list))

if self.options.get('tsv'):
return self._tsv(start, event_list)
Expand Down Expand Up @@ -1245,12 +1265,11 @@ def AgendaQuery(self, start=None, end=None):

return self._display_queried_events(start, end)

def FreeQuery(self, start=None, count=1):
def FreeQuery(self, start=None, end=None, count=1):
if not start:
start = self.now.replace(hour=0, minute=0, second=0, microsecond=0)

end = (start + timedelta(days=(count * 8)))

if not end:
end = (start + timedelta(days=(count * 8)))
return self._display_free(start, end)

def CalQuery(self, cmd, start_text='', count=1):
Expand Down

0 comments on commit 49b9a79

Please sign in to comment.