Begin nomie parser creation

This commit is contained in:
Marty Oehme 2021-12-24 22:34:49 +01:00
parent a825287642
commit bb4b85851e
Signed by: Marty
GPG key ID: B7538B8F50A1C800
4 changed files with 44 additions and 14 deletions

View file

@ -0,0 +1,10 @@
from __future__ import annotations
from json import loads as jsonloads
from habitmove.parser import Parser
class NomieParser(Parser):
def __init__(self, data="{}") -> None:
"""Load a data set and prepare parser data"""
self.data = jsonloads(data)

View file

@ -1,11 +1,22 @@
from __future__ import annotations
from pathlib import Path
from habitmove.nomiedata import Event, ImportData, Tracker
class Parser:
def parse(self, path: str, filename: str) -> ImportData:
def __init__(self, data="") -> None:
"""Load a data set and prepare parser data"""
self.data = data
@classmethod
def from_file(cls, path: str) -> Parser:
"""Load in a data set"""
txt = Path(path).read_text()
return cls(data=txt)
def parse(self) -> ImportData:
"""Extract all data from a data set"""
raise NotImplementedError
def extract_version(self) -> str:
@ -19,7 +30,3 @@ class Parser:
def extract_events(self) -> list[Event]:
"""Extract events from the data set"""
raise NotImplementedError
class NomieParser(Parser):
pass