Data improvements
This commit is contained in:
parent
9ee3113da2
commit
e7c2ea6972
|
@ -99,6 +99,10 @@ def import_step_counts_csv(vault: ObsidianVault, rows: Rows) -> int:
|
||||||
|
|
||||||
return num_updated
|
return num_updated
|
||||||
|
|
||||||
|
def escape_for_obsidian_link(link: str) -> str:
|
||||||
|
return link.replace(':', ' ').replace('/', ' ').replace(' ', ' ')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def import_watched_series_csv(vault: ObsidianVault, rows: Rows) -> int:
|
def import_watched_series_csv(vault: ObsidianVault, rows: Rows) -> int:
|
||||||
verb = 'Watched'
|
verb = 'Watched'
|
||||||
|
@ -114,6 +118,7 @@ def import_watched_series_csv(vault: ObsidianVault, rows: Rows) -> int:
|
||||||
del rows
|
del rows
|
||||||
|
|
||||||
def map_to_event(sample: RealizedActivitySample) -> Event:
|
def map_to_event(sample: RealizedActivitySample) -> Event:
|
||||||
|
noun = escape_for_obsidian_link(sample.single_label_with_category('series.name'))
|
||||||
comment = '{} Episode {}: *{}*'.format(
|
comment = '{} Episode {}: *{}*'.format(
|
||||||
sample.single_label_with_category('season.name'),
|
sample.single_label_with_category('season.name'),
|
||||||
sample.single_label_with_category('episode.index'),
|
sample.single_label_with_category('episode.index'),
|
||||||
|
@ -123,7 +128,7 @@ def import_watched_series_csv(vault: ObsidianVault, rows: Rows) -> int:
|
||||||
return Event(sample.start_at.astimezone(expected_tz).replace(second=0,microsecond=0).time(),
|
return Event(sample.start_at.astimezone(expected_tz).replace(second=0,microsecond=0).time(),
|
||||||
sample.end_at.astimezone(expected_tz).replace(second=0,microsecond=0).time(),
|
sample.end_at.astimezone(expected_tz).replace(second=0,microsecond=0).time(),
|
||||||
verb,
|
verb,
|
||||||
sample.single_label_with_category('series.name'),
|
noun,
|
||||||
comment,
|
comment,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,15 @@ StatisticKey = str
|
||||||
class Event:
|
class Event:
|
||||||
start_time: datetime.time | None
|
start_time: datetime.time | None
|
||||||
end_time: datetime.time | None
|
end_time: datetime.time | None
|
||||||
verb: str
|
verb: str | None
|
||||||
subject: str
|
subject: str | None
|
||||||
comment: str
|
comment: str
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if self.subject:
|
||||||
|
assert ':' not in self.subject
|
||||||
|
assert '/' not in self.subject
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class FileContents:
|
class FileContents:
|
||||||
|
@ -226,8 +231,8 @@ def format_event_string(event: Event) -> str:
|
||||||
|
|
||||||
RE_TIME = r'(\d\d:\d\d(?::\d\d(?:\.\d+?))?)'
|
RE_TIME = r'(\d\d:\d\d(?::\d\d(?:\.\d+?))?)'
|
||||||
RE_VERB = r'(\w+(?:ed|te))'
|
RE_VERB = r'(\w+(?:ed|te))'
|
||||||
RE_LINK_MD = r'\[([^\]]*)\]\(?:[^)]*\)'
|
RE_LINK_MD = r'\[([^\]:/]*)\]\(?:[^)]*\)'
|
||||||
RE_LINK_WIKI = r'\[\[([^\]]*)\]\]'
|
RE_LINK_WIKI = r'\[\[([^\]:/]*)\]\]'
|
||||||
|
|
||||||
RE_TIME_FORMAT = RE_TIME + r'(?:\s*\-\s*' + RE_TIME + r')?'
|
RE_TIME_FORMAT = RE_TIME + r'(?:\s*\-\s*' + RE_TIME + r')?'
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ EXAMPLES = [
|
||||||
obsidian.Event(datetime.time(20, 0, 0), datetime.time(22, 0, 0),
|
obsidian.Event(datetime.time(20, 0, 0), datetime.time(22, 0, 0),
|
||||||
"Watched", "Tom and Jerry", "on the *Television*"),
|
"Watched", "Tom and Jerry", "on the *Television*"),
|
||||||
obsidian.Event(None, None, None, None, "Took a walk"),
|
obsidian.Event(None, None, None, None, "Took a walk"),
|
||||||
|
obsidian.Event(None, None, None, None, "Watched [[Cyberpunk: Edgerunners]]."),
|
||||||
]
|
]
|
||||||
|
|
||||||
@pytest.mark.parametrize("event", EXAMPLES)
|
@pytest.mark.parametrize("event", EXAMPLES)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user