From b3ee0ad66a8c63d9e14b2faa27b20f66bac9d770 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 9 Jun 2026 11:09:29 +0200 Subject: [PATCH] [IMP] search_flows_parsed(): updated_after can now be a datetime object (timezone aware or timezone naive as UTC) --- README.md | 6 ++++-- src/pyfrctc/pyfrctc.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1cce668..f9562e6 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ This library is published under the [GNU Lesser General Public License v2.1](htt ## Changelog +* version 0.8 dated 2026-06-09 + + * search\_flows\_parsed() now accepts updated\_after as datetime object (timezone aware or timezone naive as UTC) + * version 0.7 dated 2026-05-28 ([OCA code sprint in Santander](https://www.aeodoo.org/event/spanish-oca-days-2026-143/page/introduccion-spanish-oca-days-2026)) * Restore method get\_session() @@ -49,5 +53,3 @@ This library is published under the [GNU Lesser General Public License v2.1](htt * version 0.1 dated 2026-04-22 * initial release - - diff --git a/src/pyfrctc/pyfrctc.py b/src/pyfrctc/pyfrctc.py index 33de95c..6dd8128 100644 --- a/src/pyfrctc/pyfrctc.py +++ b/src/pyfrctc/pyfrctc.py @@ -861,7 +861,14 @@ def search_flows( raise ValueError("session argument has no value") if not updated_after: raise ValueError("updated_after argument must have a value") - # TODO add check for updated_after ? + if not isinstance(updated_after, str): + raise ValueError("updated_after argument must be a timestamp as string") + if not updated_after.endswith("Z"): + raise ValueError( + "updated_after argument must be a timestamp as string in UTC, " + "so it should end with 'Z'" + ) + if flow_direction: if isinstance(flow_direction, str): flow_direction = [flow_direction] @@ -970,6 +977,15 @@ def search_flows_parsed( flow_direction = flow_direction.capitalize() elif isinstance(flow_direction, list): flow_direction = [x.capitalize() for x in flow_direction] + if isinstance(updated_after, datetime.datetime): + if updated_after.tzinfo: # tz aware + updated_after_utc_aware = updated_after.astimezone(pytz.utc) + else: # tz naive, we suppose it is UTC + updated_after_utc_aware = pytz.utc.localize(updated_after) + updated_after = updated_after_utc_aware.isoformat(timespec="milliseconds") + if updated_after.endswith("+00:00"): + updated_after = f"{updated_after[:-6]}Z" + logger.debug(f"updated_after converted to string: {updated_after}") res = search_flows( session, updated_after, flow_direction, flow_type, updated_before=updated_before )