Skip to content

Commit

Permalink
fix: add file encoding support to csvreader
Browse files Browse the repository at this point in the history
fixed support for importers on non-UTF8 (e.g. Shift-JIS) text files.

Fixes #99.
  • Loading branch information
awtimmering committed Apr 7, 2024
1 parent 246427f commit 9b2e909
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions beancount_reds_importers/libreader/csvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def initialize_reader(self, file):
# print(self.header_identifier, file.head())

def deep_identify(self, file):
return re.match(self.header_identifier, file.head())
return re.match(
self.header_identifier,
file.head(encoding=getattr(self, "file_encoding", None)),
)

def file_date(self, file):
"Get the maximum date from the file."
Expand Down Expand Up @@ -135,7 +138,7 @@ def convert_date(d):
return rdr

def read_raw(self, file):
return etl.fromcsv(file.name)
return etl.fromcsv(file.name, encoding=getattr(self, "file_encoding", None))

def skip_until_main_table(self, rdr, col_labels=None):
"""Skip csv lines until the header line is found."""
Expand Down
6 changes: 3 additions & 3 deletions beancount_reds_importers/libtransactionbuilder/investments.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def generate_trade_entry(self, ot, file, counter):
if "sell" in ot.type:
units = -1 * abs(ot.units)
if not is_money_market:
metadata[
"todo"
] = "TODO: this entry is incomplete until lots are selected (bean-doctor context <filename> <lineno>)" # noqa: E501
metadata["todo"] = (
"TODO: this entry is incomplete until lots are selected (bean-doctor context <filename> <lineno>)" # noqa: E501
)
if ot.type in [
"reinvest"
]: # dividends are booked to commodity_leaf. Eg: Income:Dividends:HOOLI
Expand Down

0 comments on commit 9b2e909

Please sign in to comment.