Skip to content

Commit

Permalink
Handle whatsapp style file names with underscore and without the last…
Browse files Browse the repository at this point in the history
… group
  • Loading branch information
derneuere committed Jun 14, 2023
1 parent bfc19c0 commit 96bb1eb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/date_time_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _regexp_group_range(a, b):
# Here we get year, month, day from the filename and use the number as microsecond so that
# media is ordered by that number but all of these images are grouped together separated from
# other media on that date.
REGEXP_WHATSAPP = re.compile(r"^(?:IMG|VID)-(\d{4})(\d{2})(\d{2})-WA(\d+)")
REGEXP_WHATSAPP = re.compile(r"^(?:IMG|VID)[-_](\d{4})(\d{2})(\d{2})(?:[-_]WA(\d+))?")
REGEXP_WHATSAPP_GROUP_MAPPING = ["year", "month", "day", "microsecond"]

PREDEFINED_REGEXPS = {
Expand Down Expand Up @@ -88,7 +88,9 @@ def _extract_no_tz_datetime_from_str(x, regexp=REGEXP_NO_TZ, group_mapping=None)
f"Group mapping {how_to_use} is unknown - must be one of {list(REGEXP_GROUP_MAPPINGS.keys())}"
)
ind = REGEXP_GROUP_MAPPINGS[how_to_use]
datetime_args[ind] = int(value)
# handle case when we have less groups than expected
if value is not None:
datetime_args[ind] = int(value)

try:
return datetime(*datetime_args)
Expand Down

0 comments on commit 96bb1eb

Please sign in to comment.