Created
June 13, 2024 11:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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