Created
May 28, 2024 11:59
-
-
Save acsr/78e4ce6b90babf195ab17b7428d2fa06 to your computer and use it in GitHub Desktop.
Filter out the [[datetime]] default String from a GoFullscreen [[Screenshot]]
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 GoFullscreen Screenshot Timestamps.py | |
Filter out the [[datetime]] default String from a GoFullscreen [[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 20231109_163157-acsr (based on "Remove macOS Screenshot DE Timestamps.py") | |
20240527_151450 by Armin Stross-Radschinski, acsr.github@dev.acsr.de for acsr/evenios | |
""" | |
import sys | |
import re | |
#example_str = "screencapture-Something totally different-2023-11-26-10_56_05.png" | |
regex1 = r"\s*-\d\d\d\d-\d\d-\d\d-\d\d_\d\d_\d\d\s*" | |
regex2 = r"\s*screencapture-\s*" # removes Prefix "screencapture-" | |
subst = "" | |
def extract_datetime(filename): | |
"""We extract the machting pattern""" | |
result = re.search(regex1, filename) | |
if result: | |
result = result.group(0).strip().replace("-", "", 3).replace("_", "", 2).replace("-", "_", 1) | |
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