feat: extract date & time from tags
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
ee91b2e8db
commit
d5b1541436
6 changed files with 246 additions and 22 deletions
|
|
@ -1,19 +1,29 @@
|
|||
from datetime import datetime
|
||||
|
||||
from streamer.parse.shard import Shard, StreamFile
|
||||
|
||||
from .repostory_configuration import RepositoryConfiguration
|
||||
from .extract_datetime import (
|
||||
extract_datetime_from_file_name,
|
||||
extract_datetime_from_marker_list,
|
||||
)
|
||||
from .localized_shard import LocalizedShard
|
||||
from .extract_datetime import extract_date_from_file_name
|
||||
from .repostory_configuration import RepositoryConfiguration
|
||||
|
||||
|
||||
def localize_shard(
|
||||
shard: Shard, config: RepositoryConfiguration, propagated: dict[str, str]
|
||||
shard: Shard,
|
||||
config: RepositoryConfiguration,
|
||||
propagated: dict[str, str],
|
||||
moment: datetime,
|
||||
) -> LocalizedShard:
|
||||
position = {**propagated}
|
||||
private_position: dict[str, str] = {}
|
||||
|
||||
adjusted_moment: datetime = extract_datetime_from_marker_list(shard.markers, moment)
|
||||
|
||||
for marker in shard.markers:
|
||||
normalized_marker = marker.lower()
|
||||
|
||||
if marker_definition := config.markers[normalized_marker]:
|
||||
dimension_name = marker_definition.dimension
|
||||
dimension = config.dimensions[marker_definition.dimension]
|
||||
|
|
@ -23,24 +33,30 @@ def localize_shard(
|
|||
else:
|
||||
private_position[dimension_name] = normalized_marker
|
||||
|
||||
children = [localize_shard(child, config, position) for child in shard.children]
|
||||
children = [
|
||||
localize_shard(child, config, position, adjusted_moment)
|
||||
for child in shard.children
|
||||
]
|
||||
|
||||
position.update(private_position)
|
||||
|
||||
return LocalizedShard(
|
||||
**shard.model_dump(exclude={"children"}), location=position, children=children
|
||||
**shard.model_dump(exclude={"children"}),
|
||||
location=position,
|
||||
children=children,
|
||||
moment=adjusted_moment,
|
||||
)
|
||||
|
||||
|
||||
def localize_stream_file(
|
||||
stream_file: StreamFile, config: RepositoryConfiguration
|
||||
) -> LocalizedShard | None:
|
||||
shard_date = extract_date_from_file_name(stream_file.filename)
|
||||
shard_date = extract_datetime_from_file_name(stream_file.filename)
|
||||
|
||||
if not shard_date or not stream_file.shard:
|
||||
raise ValueError("Could not extract date")
|
||||
|
||||
return localize_shard(stream_file.shard, config, {"moment": shard_date.isoformat()})
|
||||
return localize_shard(stream_file.shard, config, {}, shard_date)
|
||||
|
||||
|
||||
__all__ = ["localize_stream_file"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue