-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
30 lines (22 loc) · 904 Bytes
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from datetime import datetime
from fs import path
import re
def get_timestamp():
# Get current time
current_time = datetime.utcnow()
# Round down to the nearest 10 seconds
rounded_seconds = current_time.second // 10 * 10
# Create a new datetime object with the rounded down seconds
rounded_time = current_time.replace(second=rounded_seconds, microsecond=0)
# Return the time as a string
return rounded_time.strftime("%Y-%m-%d %H:%M:%S")
def make_filename_friendly(filename):
# Remove invalid characters
filename = re.sub(r'[\\/:\*\?"<>|]', "", filename)
# Replace reserved characters
filename = filename.replace("\\", "-")
# Remove leading/trailing whitespace and replace remaining whitespace with a hyphen
filename = re.sub(r"\s+", "-", filename.strip())
# Normalize case (optional)
filename = filename.lower()
return filename