Skip to content

Commit

Permalink
search_bsky: ignore dates if unable to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-wahl committed Feb 19, 2025
1 parent 68db315 commit 7e1f7fb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions datasources/bsky/search_bsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,20 +604,30 @@ def map_item(item):
"author_display_name": item["author"]["display_name"],
"author_profile": author_profile,
"author_avatar": item["author"]["avatar"],
"author_created_at": SearchBluesky.bsky_convert_datetime_string(item["author"]["created_at"]).isoformat(),
"author_created_at": SearchBluesky.bsky_convert_datetime_string(item["author"]["created_at"], mode="iso_string"),

"timestamp": created_at.timestamp(),
}, message=f"Bluesky new mappings: {unmapped_data}")

@staticmethod
def bsky_convert_datetime_string(datetime_string):
def bsky_convert_datetime_string(datetime_string, mode="datetime"):
"""
Bluesky datetime string to datetime object
Bluesky datetime string to datetime object. If unable to parse, return the string.
:param str datetime_string: The datetime string to convert
:param str mode: The mode to return the datetime object in [datetime, iso_string]
:return datetime: The converted datetime object
"""
return parser.isoparse(datetime_string)
try:
datetime_object = parser.isoparse(datetime_string)
except ValueError:
return datetime_string

if mode == "datetime":
return datetime_object
elif mode == "iso_string":
return datetime_object.isoformat()


@staticmethod
def get_bsky_link(handle, post_id):
Expand Down

0 comments on commit 7e1f7fb

Please sign in to comment.