diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-02-02 21:28:12 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-02-02 21:28:12 +0200 |
| commit | ae6c39c8e9758172c92136128c811f2387531228 (patch) | |
| tree | 32e89f3402d62e6f0aea79fe423c99837f090f8b /attain_vocab_to_anki_py/io.py | |
| parent | 1a1dc2a9dc2380fd04fa2f2da18ff9e6ac87647d (diff) | |
Rename to kanji_info_fetcher
Diffstat (limited to 'attain_vocab_to_anki_py/io.py')
| -rw-r--r-- | attain_vocab_to_anki_py/io.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/attain_vocab_to_anki_py/io.py b/attain_vocab_to_anki_py/io.py deleted file mode 100644 index 90c9507..0000000 --- a/attain_vocab_to_anki_py/io.py +++ /dev/null @@ -1,50 +0,0 @@ -from os import path -from dataclasses import dataclass - -@dataclass -class Entry: - kanji: str - hiragana: str - english: str - meanings: str - -def read_from_file(path_str: str, row_format: str) -> list: - p = path.join(path_str) - lines = [] - - format_segments = row_format.split(",") - - with open(p, "r") as f: - lines = f.readlines() - - entries = [] - for line in lines: - if len(line.strip()) == 0: - continue - - value_dict = {} - - row_values = line.split(",", len(format_segments) - 1) - for i, format_segment in enumerate(format_segments): - value_dict[format_segment] = row_values[i] - - entries.append(Entry( - kanji=value_dict.get("kanji", "").strip(), - hiragana=value_dict.get("hiragana", "").strip(), - english=value_dict.get("english", "").strip(), - meanings=value_dict.get("meanings", "").strip() - )) - - return entries - -def _entry_to_row(entry: Entry, delimiter: str = "ยง") -> str: - s = delimiter.join([entry.kanji, entry.hiragana, entry.english, entry.meanings]) - return f"{s}\n" - -def write_to_file(path_str: str, entries: list): - p = path.join(path_str) - - lines = map(_entry_to_row, entries) - - with open(p, "w") as f: - f.writelines(lines) |
