CSV取込機能を実装し、Expenseモデルと関連するStore・ExpenseCategoryモデルを追加。CSVパーサーを作成し、出光CSVに対応。明細編集画面のAJAX保存機能を実装し、取込結果を表示する機能を追加。作業ログをdiary.mdに追記。
This commit is contained in:
26
expenses/csv_parsers/factory.py
Normal file
26
expenses/csv_parsers/factory.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
from .base import CSVParserBase
|
||||
from .idemitsu import IdemitsuParser
|
||||
|
||||
|
||||
PARSERS: list[CSVParserBase] = [
|
||||
IdemitsuParser(),
|
||||
]
|
||||
|
||||
|
||||
def detect_parser(lines: Iterable[str]) -> CSVParserBase | None:
|
||||
for line in lines:
|
||||
for parser in PARSERS:
|
||||
if parser.detect(line):
|
||||
return parser
|
||||
return None
|
||||
|
||||
|
||||
def get_parser(lines: Iterable[str]) -> CSVParserBase:
|
||||
parser = detect_parser(lines)
|
||||
if parser is None:
|
||||
raise ValueError('CSVブランドを判定できませんでした。')
|
||||
return parser
|
||||
Reference in New Issue
Block a user