Skip to content

Instantly share code, notes, and snippets.

@acsr
Created June 13, 2024 11:12
Show Gist options
  • Save acsr/4d5d929d8543e174a6e46575eab8758f to your computer and use it in GitHub Desktop.
Save acsr/4d5d929d8543e174a6e46575eab8758f to your computer and use it in GitHub Desktop.
Filter out the [[datetime]] default String from a Firefox [[Screenshot]] and move the timestamp to the front in ISO Format
#!/usr/bin/env python3
"""Remove Firefox Screenshot Timestamps.py
Filter out the [[datetime]] default String from a Firefox [[Screenshot]]
@Copyright 2022-2024 by Armin Stross-Radschinski, ACSR industrialdesign developer@acsr.de
Licence: MIT, do what you like
Have fun
V 0.1.0 20240613_125327-acsr (based on "Remove GoFullscreen Screenshot Timestamps.py" 0.1.0)
20240613_125327- by Armin Stross-Radschinski, acsr.github@dev.acsr.de for acsr/evenios
"""
import sys
import re
#example_str = "Screenshot 2024-05-31 at 15-42-45.png"
regex1 = r"\s* \d\d\d\d-\d\d-\d\d at \d\d-\d\d-\d\d\s*"
regex2 = r"\s* Screenshot \s*" # removes Prefix "Screenshot "
subst = ""
def extract_datetime(filename):
"""We extract the machting pattern"""
result = re.search(regex1, filename)
if result:
result = result.group(0).strip().replace("-", "").replace(" at ", "_")
return result+"-"
else:
return ""
def remove_datetime(filename):
"""You can manually specify the number of replacements by changing the 4th argument"""
result = re.sub(regex1, subst, filename, 1)
if result:
return result
else:
return filename
def remove_prefix(filename):
"""You can manually specify the number of replacements by changing the 4th argument"""
result = re.sub(regex2, subst, filename, 1)
if result:
return result
else:
return filename
for filename in sys.stdin:
datetimeprefix = extract_datetime(filename)
croppedfilename = remove_datetime(filename)
croppedfilename = remove_prefix(croppedfilename)
adddatetimeprefix = datetimeprefix+croppedfilename
print(adddatetimeprefix, end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment