feat: add initial support for positioning
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
28dc40ebf0
commit
0c61067db0
9 changed files with 186 additions and 3 deletions
21
src/streamer/localize/extract_datetime.py
Normal file
21
src/streamer/localize/extract_datetime.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from datetime import datetime
|
||||
import re
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def extract_date_from_file_name(file_name: str) -> Optional[datetime]:
|
||||
FILE_NAME_REGEX = r"^(?P<date>\d{8})(?:-(?P<time>\d{4,6}))?.+.md$"
|
||||
base_name = os.path.basename(file_name)
|
||||
match = re.match(FILE_NAME_REGEX, base_name)
|
||||
|
||||
if match:
|
||||
date_str = match.group("date")
|
||||
time_str = match.group("time") or ""
|
||||
time_str = time_str.ljust(6, "0")
|
||||
datetime_str = f"{date_str} {time_str[:2]}:{time_str[2:4]}:{time_str[4:]}"
|
||||
return datetime.strptime(datetime_str, "%Y%m%d %H:%M:%S")
|
||||
return None
|
||||
|
||||
|
||||
__all__ = ["extract_date_from_file_name"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue