Skip to content

Commit

Permalink
style: reformat to 99 col width (previously 88 col)
Browse files Browse the repository at this point in the history
  • Loading branch information
redstreet committed Apr 4, 2024
1 parent cc214e2 commit 246427f
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 192 deletions.
4 changes: 1 addition & 3 deletions beancount_reds_importers/importers/amazongc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def extract(self, file, existing_entries=None):
data.EMPTY_SET,
[],
)
data.create_simple_posting(
entry, config["main_account"], number, self.currency
)
data.create_simple_posting(entry, config["main_account"], number, self.currency)
data.create_simple_posting(entry, config["target_account"], None, None)
new_entries.append(entry)

Expand Down
8 changes: 4 additions & 4 deletions beancount_reds_importers/importers/dcu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = ".*Account_Transactions"
self.header_identifier = ""
self.column_labels_line = '"DATE","TRANSACTION TYPE","DESCRIPTION","AMOUNT","ID","MEMO","CURRENT BALANCE"'
self.column_labels_line = (
'"DATE","TRANSACTION TYPE","DESCRIPTION","AMOUNT","ID","MEMO","CURRENT BALANCE"'
)
self.date_format = "%m/%d/%Y"
# fmt: off
self.header_map = {
Expand All @@ -35,6 +37,4 @@ def get_balance_statement(self, file=None):

date = self.get_balance_assertion_date()
if date:
yield banking.Balance(
date, self.rdr.namedtuples()[0].balance, self.currency
)
yield banking.Balance(date, self.rdr.namedtuples()[0].balance, self.currency)
8 changes: 2 additions & 6 deletions beancount_reds_importers/importers/fidelity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ def custom_init(self):
self.max_rounding_error = 0.18
self.filename_pattern_def = ".*fidelity"
self.get_ticker_info = self.get_ticker_info_from_id
self.get_payee = (
lambda ot: ot.memo.split(";", 1)[0] if ";" in ot.memo else ot.memo
)
self.get_payee = lambda ot: ot.memo.split(";", 1)[0] if ";" in ot.memo else ot.memo

def security_narration(self, ot):
ticker, ticker_long_name = self.get_ticker_info(ot.security)
return f"[{ticker}]"

def file_name(self, file):
return "fidelity-{}-{}".format(
self.config["account_number"], ntpath.basename(file.name)
)
return "fidelity-{}-{}".format(self.config["account_number"], ntpath.basename(file.name))

def get_target_acct_custom(self, transaction, ticker=None):
if transaction.memo.startswith("CONTRIBUTION"):
Expand Down
12 changes: 5 additions & 7 deletions beancount_reds_importers/importers/fidelity/fidelity_cma_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = ".*History"
self.date_format = "%m/%d/%Y"
header_s0 = ".*Run Date,Action,Symbol,Security Description,Security Type,Quantity,Price \\(\\$\\),"
header_s0 = (
".*Run Date,Action,Symbol,Security Description,Security Type,Quantity,Price \\(\\$\\),"
)
header_s1 = "Commission \\(\\$\\),Fees \\(\\$\\),Accrued Interest \\(\\$\\),Amount \\(\\$\\),Settlement Date"
header_sum = header_s0 + header_s1
self.header_identifier = header_sum
Expand Down Expand Up @@ -42,12 +44,8 @@ def prepare_raw_columns(self, rdr):
for field in ["Action"]:
rdr = rdr.convert(field, lambda x: x.lstrip())

rdr = rdr.capture(
"Action", "(?:\\s)(?:\\w*)(.*)", ["memo"], include_original=True
)
rdr = rdr.capture(
"Action", "(\\S+(?:\\s+\\S+)?)", ["payee"], include_original=True
)
rdr = rdr.capture("Action", "(?:\\s)(?:\\w*)(.*)", ["memo"], include_original=True)
rdr = rdr.capture("Action", "(\\S+(?:\\s+\\S+)?)", ["payee"], include_original=True)

for field in ["memo", "payee"]:
rdr = rdr.convert(field, lambda x: x.lstrip())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = ".*_Transactions_"
self.header_identifier = ""
self.column_labels_line = '"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount"'
self.column_labels_line = (
'"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount"'
)
self.get_ticker_info = self.get_ticker_info_from_id
self.date_format = "%m/%d/%Y"
self.funds_db_txt = "funds_by_ticker"
Expand Down Expand Up @@ -59,10 +61,7 @@ def custom_init(self):

def deep_identify(self, file):
last_three = self.config.get("account_number", "")[-3:]
return (
re.match(self.header_identifier, file.head())
and f"XX{last_three}" in file.name
)
return re.match(self.header_identifier, file.head()) and f"XX{last_three}" in file.name

def skip_transaction(self, ot):
return ot.type in ["", "Journal"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ def get_balance_statement(self, file=None):

date = self.get_balance_assertion_date()
if date:
yield banking.Balance(
date, self.rdr.namedtuples()[0].balance, self.currency
)
yield banking.Balance(date, self.rdr.namedtuples()[0].balance, self.currency)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class Importer(schwab_csv_checking.Importer):
def custom_init(self):
super().custom_init()
self.filename_pattern_def = ".*_Transactions_"
self.column_labels_line = '"Date","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"'
self.column_labels_line = (
'"Date","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"'
)
11 changes: 4 additions & 7 deletions beancount_reds_importers/importers/stanchart/scbbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Importer(csvreader.Importer, banking.Importer):
def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = "AccountTransactions[0-9]*"
self.header_identifier = self.config.get(
"custom_header", "Account transactions shown:"
self.header_identifier = self.config.get("custom_header", "Account transactions shown:")
self.column_labels_line = (
"Date,Transaction,Currency,Deposit,Withdrawal,Running Balance,SGD Equivalent Balance"
)
self.column_labels_line = "Date,Transaction,Currency,Deposit,Withdrawal,Running Balance,SGD Equivalent Balance"
self.balance_column_labels_line = (
"Account Name,Account Number,Currency,Current Balance,Available Balance"
)
Expand All @@ -40,10 +40,7 @@ def custom_init(self):

def deep_identify(self, file):
account_number = self.config.get("account_number", "")
return (
re.match(self.header_identifier, file.head())
and account_number in file.head()
)
return re.match(self.header_identifier, file.head()) and account_number in file.head()

# TODO: move into utils, since this is probably a common operation
def prepare_table(self, rdr):
Expand Down
17 changes: 4 additions & 13 deletions beancount_reds_importers/importers/stanchart/scbcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def custom_init(self):

def deep_identify(self, file):
account_number = self.config.get("account_number", "")
return (
re.match(self.header_identifier, file.head())
and account_number in file.head()
)
return re.match(self.header_identifier, file.head()) and account_number in file.head()

def skip_transaction(self, row):
return "[UNPOSTED]" in row.payee
Expand All @@ -59,19 +56,13 @@ def prepare_table(self, rdr):
rdr = rdr.cutout("Foreign Currency Amount")

# parse SGD Amount: "SGD 141.02 CR" into a single amount column
rdr = rdr.capture(
"SGD Amount", "(.*) (.*) (.*)", ["currency", "amount", "crdr"]
)
rdr = rdr.capture("SGD Amount", "(.*) (.*) (.*)", ["currency", "amount", "crdr"])

# change DR into -ve. TODO: move this into csvreader or csvreader.utils
crdrdict = {"DR": "-", "CR": ""}
rdr = rdr.convert(
"amount", lambda i, row: crdrdict[row.crdr] + i, pass_row=True
)
rdr = rdr.convert("amount", lambda i, row: crdrdict[row.crdr] + i, pass_row=True)

rdr = rdr.addfield(
"memo", lambda x: ""
) # TODO: make this non-mandatory in csvreader
rdr = rdr.addfield("memo", lambda x: "") # TODO: make this non-mandatory in csvreader
return rdr

def prepare_raw_file(self, rdr):
Expand Down
13 changes: 5 additions & 8 deletions beancount_reds_importers/importers/unitedoverseas/uobbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def custom_init(self):
"custom_header",
"United Overseas Bank Limited.*Account Type:Uniplus Account",
)
self.column_labels_line = "Transaction Date,Transaction Description,Withdrawal,Deposit,Available Balance"
self.column_labels_line = (
"Transaction Date,Transaction Description,Withdrawal,Deposit,Available Balance"
)
self.date_format = "%d %b %Y"
# fmt: off
self.header_map = {
Expand All @@ -32,10 +34,7 @@ def custom_init(self):

def deep_identify(self, file):
account_number = self.config.get("account_number", "")
return (
re.match(self.header_identifier, file.head())
and account_number in file.head()
)
return re.match(self.header_identifier, file.head()) and account_number in file.head()

# TODO: move these into utils, since this is probably a common operation
def prepare_table(self, rdr):
Expand All @@ -47,9 +46,7 @@ def Ds(x):

rdr = rdr.addfield(
"amount",
lambda x: -1 * Ds(x["Withdrawal"])
if x["Withdrawal"] != 0
else Ds(x["Deposit"]),
lambda x: -1 * Ds(x["Withdrawal"]) if x["Withdrawal"] != 0 else Ds(x["Deposit"]),
)
rdr = rdr.addfield("memo", lambda x: "")
return rdr
Expand Down
5 changes: 1 addition & 4 deletions beancount_reds_importers/importers/unitedoverseas/uobcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def custom_init(self):

def deep_identify(self, file):
account_number = self.config.get("account_number", "")
return (
re.match(self.header_identifier, file.head())
and account_number in file.head()
)
return re.match(self.header_identifier, file.head()) and account_number in file.head()

# TODO: move into utils, since this is probably a common operation
def prepare_table(self, rdr):
Expand Down
13 changes: 3 additions & 10 deletions beancount_reds_importers/importers/unitedoverseas/uobsrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def custom_init(self):
self.header_identifier = self.config.get(
"custom_header", "United Overseas Bank Limited.*Account Type:SRS Account"
)
self.column_labels_line = (
"Transaction Date,Transaction Description,Withdrawal,Deposit"
)
self.column_labels_line = "Transaction Date,Transaction Description,Withdrawal,Deposit"
self.date_format = "%Y%m%d"
# fmt: off
self.header_map = {
Expand All @@ -32,10 +30,7 @@ def custom_init(self):

def deep_identify(self, file):
account_number = self.config.get("account_number", "")
return (
re.match(self.header_identifier, file.head())
and account_number in file.head()
)
return re.match(self.header_identifier, file.head()) and account_number in file.head()

def prepare_table(self, rdr):
# Remove carriage returns in description
Expand All @@ -46,9 +41,7 @@ def Ds(x):

rdr = rdr.addfield(
"amount",
lambda x: -1 * Ds(x["Withdrawal"])
if x["Withdrawal"] != ""
else Ds(x["Deposit"]),
lambda x: -1 * Ds(x["Withdrawal"]) if x["Withdrawal"] != "" else Ds(x["Deposit"]),
)
rdr = rdr.addfield("memo", lambda x: "")
return rdr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def extract_numbers(x):
)
rdr = rdr.pushheader(header)

rdr = rdr.addfield(
"action", lambda x: x["description"].rsplit(" ", 2)[1].strip()
)
rdr = rdr.addfield("action", lambda x: x["description"].rsplit(" ", 2)[1].strip())

for field in [
"date",
Expand Down
14 changes: 5 additions & 9 deletions beancount_reds_importers/libreader/csv_multitable_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ def read_file(self, file):

self.raw_rdr = rdr = self.read_raw(file)

rdr = rdr.skip(
getattr(self, "skip_head_rows", 0)
) # chop unwanted file header rows
rdr = rdr.skip(getattr(self, "skip_head_rows", 0)) # chop unwanted file header rows
rdr = rdr.head(
len(rdr) - getattr(self, "skip_tail_rows", 0) - 1
) # chop unwanted file footer rows

# [0, 2, 10] <-- starts
# [-1, 1, 9] <-- ends
table_starts = [
i for (i, row) in enumerate(rdr) if self.is_section_title(row)
] + [len(rdr)]
table_starts = [i for (i, row) in enumerate(rdr) if self.is_section_title(row)] + [
len(rdr)
]
table_ends = [r - 1 for r in table_starts][1:]
table_indexes = zip(table_starts, table_ends)

Expand All @@ -85,9 +83,7 @@ def read_file(self, file):

for section, table in self.alltables.items():
table = table.rowlenselect(0, complement=True) # clean up empty rows
table = table.cut(
*[h for h in table.header() if h]
) # clean up empty columns
table = table.cut(*[h for h in table.header() if h]) # clean up empty columns
self.alltables[section] = table

self.prepare_tables() # to be overridden by importer
Expand Down
4 changes: 1 addition & 3 deletions beancount_reds_importers/libreader/csvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ def read_file(self, file):
rdr = self.prepare_raw_file(rdr)

# extract main table
rdr = rdr.skip(
getattr(self, "skip_head_rows", 0)
) # chop unwanted header rows
rdr = rdr.skip(getattr(self, "skip_head_rows", 0)) # chop unwanted header rows
rdr = rdr.head(
len(rdr) - getattr(self, "skip_tail_rows", 0) - 1
) # chop unwanted footer rows
Expand Down
4 changes: 1 addition & 3 deletions beancount_reds_importers/libreader/ofxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def get_balance_assertion_date(self):

if not return_date:
return None
return return_date + datetime.timedelta(
days=1
) # Next day, as defined by Beancount
return return_date + datetime.timedelta(days=1) # Next day, as defined by Beancount

def get_max_transaction_date(self):
"""
Expand Down
4 changes: 1 addition & 3 deletions beancount_reds_importers/libreader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def identify(self, file):
# print("No match on extension")
return False
self.custom_init()
self.filename_pattern = self.config.get(
"filename_pattern", self.filename_pattern_def
)
self.filename_pattern = self.config.get("filename_pattern", self.filename_pattern_def)
if not re.match(self.filename_pattern, path.basename(file.name)):
# print("No match on filename_pattern", self.filename_pattern, path.basename(file.name))
return False
Expand Down
8 changes: 2 additions & 6 deletions beancount_reds_importers/libtransactionbuilder/banking.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def extract(self, file, existing_entries=None):
metadata = data.new_metadata(file.name, next(counter))
# metadata['type'] = ot.type # Optional metadata, useful for debugging #TODO
metadata.update(
self.build_metadata(
file, metatype="transaction", data={"transaction": ot}
)
self.build_metadata(file, metatype="transaction", data={"transaction": ot})
)

# description fields: With OFX, ot.payee tends to be the "main" description field,
Expand Down Expand Up @@ -149,9 +147,7 @@ def extract(self, file, existing_entries=None):
ot.foreign_currency,
)
else:
data.create_simple_posting(
entry, main_account, ot.amount, self.get_currency(ot)
)
data.create_simple_posting(entry, main_account, ot.amount, self.get_currency(ot))

# smart_importer can fill this in if the importer doesn't override self.get_target_acct()
target_acct = self.get_target_account(ot)
Expand Down

0 comments on commit 246427f

Please sign in to comment.