Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #99: Add option to set file encoding to CSV reader. #100

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading