Skip to content

Commit 27c23d8

Browse files
aitestinoChristopherJHart
authored andcommitted
feat: implement date handling and room message retrieval enhancements
* Added a new function `_handle_room_search_dates` to manage date parsing for room-based searches, allowing for optional date filtering. * Introduced `_run_date_range` to execute workflows over specified date ranges, improving the handling of date-based searches. * Refactored the `main` function to streamline date handling logic and integrate new date management functions. * Enhanced logging for better traceability during room-specific message retrieval processes. * Updated the `run_app` function to utilize new helper functions for improved clarity and maintainability.
1 parent d307caf commit 27c23d8

File tree

3 files changed

+280
-151
lines changed

3 files changed

+280
-151
lines changed

summarizer/cli.py

Lines changed: 124 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ def _validate_room_parameters(
7373
person_name: str | None,
7474
) -> str | None:
7575
"""Validate room-specific parameters and return the search mode.
76-
76+
7777
Returns:
7878
Search mode: 'room_id', 'room_name', 'person_name', or None if no room params.
79-
79+
8080
Raises:
8181
typer.Exit on validation error.
8282
"""
8383
room_params = [room_id, room_name, person_name]
8484
active_params = [p for p in room_params if p is not None]
85-
85+
8686
if len(active_params) > 1:
8787
typer.echo(
8888
"[red]Cannot use multiple room identification options simultaneously. "
8989
"Please choose only one of --room-id, --room-name, or --person-name.[/red]"
9090
)
9191
raise typer.Exit(1)
92-
92+
9393
if room_id:
9494
return "room_id"
9595
elif room_name:
@@ -137,6 +137,81 @@ def _validate_and_parse_dates(
137137
return parsed_date, None, None, "single"
138138

139139

140+
def _handle_room_search_dates(
141+
room_search_mode: str | None,
142+
target_date: str | None,
143+
start_date: str | None,
144+
end_date: str | None,
145+
) -> tuple[datetime | None, datetime | None, datetime | None, str | None]:
146+
"""Handle date parsing for room-based searches.
147+
148+
Returns:
149+
(parsed_target_date, parsed_start_date, parsed_end_date, date_mode)
150+
"""
151+
if room_search_mode:
152+
# Room-based search - dates are optional for filtering
153+
if target_date or start_date or end_date:
154+
return _validate_and_parse_dates(target_date, start_date, end_date)
155+
else:
156+
# No date filtering - retrieve all messages from room
157+
return None, None, None, None
158+
else:
159+
# Traditional date-based search - validate dates
160+
parsed_target_date, parsed_start_date, parsed_end_date, date_mode = (
161+
_validate_and_parse_dates(target_date, start_date, end_date)
162+
)
163+
164+
# If no explicit date provided, prompt for one
165+
if date_mode == "single" and target_date is None:
166+
parsed_target_date = _handle_single_date(None)
167+
date_mode = "single"
168+
elif parsed_target_date is None and parsed_start_date is None:
169+
typer.echo(
170+
"[red]Please specify either date-based options (--target-date, "
171+
"--start-date/--end-date) or room-based options (--room-id, "
172+
"--room-name, --person-name).[/red]"
173+
)
174+
raise typer.Exit(1)
175+
176+
return parsed_target_date, parsed_start_date, parsed_end_date, date_mode
177+
178+
179+
def _run_date_range(
180+
parsed_start_date: datetime,
181+
parsed_end_date: datetime,
182+
webex_token: str,
183+
user_email: str,
184+
context_window_minutes: int,
185+
passive_participation: bool,
186+
time_display_format: str,
187+
room_chunk_size: int,
188+
max_messages: int,
189+
room_search_mode: str | None,
190+
room_search_value: str | None,
191+
) -> None:
192+
"""Execute date range workflow."""
193+
current = parsed_start_date
194+
while current <= parsed_end_date:
195+
config = AppConfig(
196+
webex_token=webex_token,
197+
user_email=user_email,
198+
target_date=current,
199+
context_window_minutes=context_window_minutes,
200+
passive_participation=passive_participation,
201+
time_display_format=time_display_format,
202+
room_chunk_size=room_chunk_size,
203+
max_messages=max_messages,
204+
)
205+
_run_for_date(
206+
config,
207+
date_header=True,
208+
room_search_mode=room_search_mode,
209+
room_search_value=room_search_value,
210+
apply_date_filter=True,
211+
)
212+
current += timedelta(days=1)
213+
214+
140215
def _run_for_date(
141216
config: AppConfig,
142217
date_header: bool,
@@ -146,15 +221,25 @@ def _run_for_date(
146221
) -> None:
147222
logger.info("Attempting to log into Webex API as user %s", config.user_email)
148223
if room_search_mode:
149-
logger.info("Room search mode: %s with value: %s", room_search_mode, room_search_value)
224+
logger.info(
225+
"Room search mode: %s with value: %s",
226+
room_search_mode,
227+
room_search_value,
228+
)
150229
logger.info("Max messages to retrieve: %d", config.max_messages)
151230
else:
152231
logger.info("Targeted date for summarization: %s", config.target_date)
153232
logger.info("Context window size: %d minutes", config.context_window_minutes)
154233
logger.info("Passive participation: %s", config.passive_participation)
155234
logger.info("Time display format: %s", config.time_display_format)
156235
logger.info("Room fetch chunk size: %d", config.room_chunk_size)
157-
run_app(config, date_header=date_header, room_search_mode=room_search_mode, room_search_value=room_search_value, apply_date_filter=apply_date_filter)
236+
run_app(
237+
config,
238+
date_header=date_header,
239+
room_search_mode=room_search_mode,
240+
room_search_value=room_search_value,
241+
apply_date_filter=apply_date_filter,
242+
)
158243

159244

160245
@app.command()
@@ -231,9 +316,7 @@ def main(
231316
] = None,
232317
person_name: Annotated[
233318
str | None,
234-
typer.Option(
235-
help="Person name to find DM room with (exact match)"
236-
),
319+
typer.Option(help="Person name to find DM room with (exact match)"),
237320
] = None,
238321
max_messages: Annotated[
239322
int, typer.Option(help="Maximum number of messages to retrieve from room")
@@ -244,68 +327,41 @@ def main(
244327
logger.setLevel(logging.DEBUG)
245328
logger.debug("Debug logging enabled")
246329

247-
# Validate room parameters
330+
# Validate room parameters and get search mode
248331
room_search_mode = _validate_room_parameters(room_id, room_name, person_name)
249-
332+
room_search_value = room_id or room_name or person_name
333+
250334
# Handle date parameters based on whether room search is specified
251-
if room_search_mode:
252-
# Room-based search - dates are optional for filtering
253-
if target_date or start_date or end_date:
254-
parsed_target_date, parsed_start_date, parsed_end_date, date_mode = (
255-
_validate_and_parse_dates(target_date, start_date, end_date)
256-
)
257-
else:
258-
# No date filtering - retrieve all messages from room
259-
parsed_target_date, parsed_start_date, parsed_end_date, date_mode = None, None, None, None
260-
else:
261-
# Traditional date-based search - validate dates
262-
parsed_target_date, parsed_start_date, parsed_end_date, date_mode = (
263-
_validate_and_parse_dates(target_date, start_date, end_date)
264-
)
265-
266-
# If no explicit date provided, prompt for one
267-
if date_mode == "single" and target_date is None:
268-
parsed_target_date = _handle_single_date(None)
269-
date_mode = "single"
270-
elif parsed_target_date is None and parsed_start_date is None:
271-
typer.echo(
272-
"[red]Please specify either date-based options (--target-date, "
273-
"--start-date/--end-date) or room-based options (--room-id, "
274-
"--room-name, --person-name).[/red]"
275-
)
276-
raise typer.Exit(1)
335+
parsed_target_date, parsed_start_date, parsed_end_date, date_mode = (
336+
_handle_room_search_dates(room_search_mode, target_date, start_date, end_date)
337+
)
277338

278-
# Get room search value for room-based searches
279-
room_search_value = room_id or room_name or person_name
280-
339+
# Handle date range mode
281340
if date_mode == "range":
282-
# Iterate over date range (inclusive)
283-
current = parsed_start_date
284-
if current is None or parsed_end_date is None:
341+
if parsed_start_date is None or parsed_end_date is None:
285342
raise ValueError(
286343
"Both start_date and end_date must be provided for range mode"
287344
)
288-
while current <= parsed_end_date:
289-
config = AppConfig(
290-
webex_token=webex_token,
291-
user_email=user_email,
292-
target_date=current,
293-
context_window_minutes=context_window_minutes,
294-
passive_participation=passive_participation,
295-
time_display_format=time_display_format.value,
296-
room_chunk_size=room_chunk_size,
297-
max_messages=max_messages,
298-
)
299-
_run_for_date(config, date_header=True, room_search_mode=room_search_mode, room_search_value=room_search_value, apply_date_filter=True)
300-
current += timedelta(days=1)
345+
_run_date_range(
346+
parsed_start_date,
347+
parsed_end_date,
348+
webex_token,
349+
user_email,
350+
context_window_minutes,
351+
passive_participation,
352+
time_display_format.value,
353+
room_chunk_size,
354+
max_messages,
355+
room_search_mode,
356+
room_search_value,
357+
)
301358
return
302359

303360
# Single date mode or room-only mode
304361
if parsed_target_date is None and not room_search_mode:
305-
# Traditional date-based mode requires a date
306362
raise ValueError("Target date must be provided for single date mode")
307-
308-
# Construct AppConfig
363+
364+
# Construct AppConfig and run
309365
config = AppConfig(
310366
webex_token=webex_token,
311367
user_email=user_email,
@@ -316,11 +372,17 @@ def main(
316372
room_chunk_size=room_chunk_size,
317373
max_messages=max_messages,
318374
)
375+
319376
# Determine if we should apply date filtering
320-
# Only skip date filtering for room-only searches (room specified but no date params)
321377
should_apply_date_filter = not (room_search_mode and parsed_target_date is None)
322-
323-
_run_for_date(config, date_header=False, room_search_mode=room_search_mode, room_search_value=room_search_value, apply_date_filter=should_apply_date_filter)
378+
379+
_run_for_date(
380+
config,
381+
date_header=False,
382+
room_search_mode=room_search_mode,
383+
room_search_value=room_search_value,
384+
apply_date_filter=should_apply_date_filter,
385+
)
324386

325387

326388
if __name__ == "__main__":

0 commit comments

Comments
 (0)