Skip to content

Commit

Permalink
feat: format all files with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ranebrown committed Mar 22, 2024
1 parent 169f62a commit facce82
Show file tree
Hide file tree
Showing 60 changed files with 870 additions and 832 deletions.
14 changes: 7 additions & 7 deletions beancount_reds_importers/example/fund_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
# mutual funds since those are brokerage specific.

fund_data = [
('SCHF', '808524805', 'Schwab International Equity ETF'),
('VGTEST', '012345678', 'Vanguard Test Fund'),
('VMFXX', '922906300', 'Vanguard Federal Money Market Fund'),
("SCHF", "808524805", "Schwab International Equity ETF"),
("VGTEST", "012345678", "Vanguard Test Fund"),
("VMFXX", "922906300", "Vanguard Federal Money Market Fund"),
]

# list of money_market accounts. These will not be held at cost, and instead will use price conversions
money_market = ['VMFXX']
money_market = ["VMFXX"]

fund_info = {
'fund_data': fund_data,
'money_market': money_market,
}
"fund_data": fund_data,
"money_market": money_market,
}
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/alliant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Alliant Credit Union'
IMPORTER_NAME = "Alliant Credit Union"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*alliant'
self.filename_pattern_def = ".*alliant"
self.custom_init_run = True
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/ally/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Ally Bank'
IMPORTER_NAME = "Ally Bank"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*transactions'
self.filename_pattern_def = ".*transactions"
self.custom_init_run = True
29 changes: 14 additions & 15 deletions beancount_reds_importers/importers/amazongc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@
class Importer(importer.ImporterProtocol):
def __init__(self, config):
self.config = config
self.currency = self.config.get('currency', 'CURRENCY_NOT_CONFIGURED')
self.filename_pattern_def = 'amazon-gift-card.tsv'
self.currency = self.config.get("currency", "CURRENCY_NOT_CONFIGURED")
self.filename_pattern_def = "amazon-gift-card.tsv"

def identify(self, file):
return self.filename_pattern_def in file.name

def file_name(self, file):
return '{}'.format(ntpath.basename(file.name))
return "{}".format(ntpath.basename(file.name))

def file_account(self, _):
return self.config['main_account']
return self.config["main_account"]

def file_date(self, file):
"Get the maximum date from the file."
maxdate = datetime.date.min
for line in open(file.name, 'r').readlines()[1:]:
f = line.split('\t')
for line in open(file.name, "r").readlines()[1:]:
f = line.split("\t")
f = [i.strip() for i in f]
date = datetime.datetime.strptime(f[0], '%B %d, %Y').date()
date = datetime.datetime.strptime(f[0], "%B %d, %Y").date()
maxdate = max(date, maxdate)
return maxdate

Expand All @@ -65,18 +65,17 @@ def extract(self, file, existing_entries=None):
new_entries = []

counter = itertools.count()
for line in open(file.name, 'r').readlines()[1:]:
f = line.split('\t')
for line in open(file.name, "r").readlines()[1:]:
f = line.split("\t")
f = [i.strip() for i in f]
date = datetime.datetime.strptime(f[0], '%B %d, %Y').date()
date = datetime.datetime.strptime(f[0], "%B %d, %Y").date()
description = f[1].encode("ascii", "ignore").decode()
number = D(f[2].replace('$', ''))
number = D(f[2].replace("$", ""))

metadata = data.new_metadata(file.name, next(counter))
entry = data.Transaction(metadata, date, self.FLAG,
None, description, data.EMPTY_SET, data.EMPTY_SET, [])
data.create_simple_posting(entry, config['main_account'], number, self.currency)
data.create_simple_posting(entry, config['target_account'], None, None)
entry = data.Transaction(metadata, date, self.FLAG, None, description, data.EMPTY_SET, data.EMPTY_SET, [])
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)

return new_entries
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/amex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'American Express'
IMPORTER_NAME = "American Express"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*amex'
self.filename_pattern_def = ".*amex"
self.custom_init_run = True
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/becu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'BECU'
IMPORTER_NAME = "BECU"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*becu'
self.filename_pattern_def = ".*becu"
self.custom_init_run = True
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/capitalonebank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Capital One Bank'
IMPORTER_NAME = "Capital One Bank"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*360Checking'
self.filename_pattern_def = ".*360Checking"
self.custom_init_run = True
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/chase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Chase'
IMPORTER_NAME = "Chase"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*[Cc]hase'
self.filename_pattern_def = ".*[Cc]hase"
self.custom_init_run = True
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/citi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Citi'
IMPORTER_NAME = "Citi"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*citi'
self.filename_pattern_def = ".*citi"
self.custom_init_run = True
4 changes: 1 addition & 3 deletions beancount_reds_importers/importers/dcu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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)
22 changes: 11 additions & 11 deletions beancount_reds_importers/importers/discover/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Discover credit card .csv importer."""
"""Discover credit card .csv importer."""

from beancount_reds_importers.libreader import csvreader
from beancount_reds_importers.libtransactionbuilder import banking
Expand All @@ -9,21 +9,21 @@ class Importer(csvreader.Importer, banking.Importer):

def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = 'Discover.*'
self.header_identifier = 'Trans. Date,Post Date,Description,Amount,Category'
self.date_format = '%m/%d/%Y'
self.filename_pattern_def = "Discover.*"
self.header_identifier = "Trans. Date,Post Date,Description,Amount,Category"
self.date_format = "%m/%d/%Y"
self.header_map = {
"Category": 'payee',
"Description": 'memo',
"Trans. Date": 'date',
"Post Date": 'postDate',
"Amount": 'amount',
}
"Category": "payee",
"Description": "memo",
"Trans. Date": "date",
"Post Date": "postDate",
"Amount": "amount",
}

def skip_transaction(self, ot):
return False

def prepare_processed_table(self, rdr):
# Need to invert numbers supplied by Discover
rdr = rdr.convert('amount', lambda x: -1 * x)
rdr = rdr.convert("amount", lambda x: -1 * x)
return rdr
4 changes: 2 additions & 2 deletions beancount_reds_importers/importers/discover/discover_ofx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class Importer(banking.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Discover'
IMPORTER_NAME = "Discover"

def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*Discover'
self.filename_pattern_def = ".*Discover"
self.custom_init_run = True
8 changes: 4 additions & 4 deletions beancount_reds_importers/importers/etrade/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
""" ETrade Brokerage ofx importer."""
"""ETrade Brokerage ofx importer."""

from beancount_reds_importers.libreader import ofxreader
from beancount_reds_importers.libtransactionbuilder import investments


class Importer(investments.Importer, ofxreader.Importer):
IMPORTER_NAME = 'ETrade Brokerage OFX'
IMPORTER_NAME = "ETrade Brokerage OFX"

def custom_init(self):
self.max_rounding_error = 0.11
self.filename_pattern_def = '.*etrade'
self.filename_pattern_def = ".*etrade"
self.get_ticker_info = self.get_ticker_info_from_id

def skip_transaction(self, ot):
if 'JNL' in ot.memo:
if "JNL" in ot.memo:
return True
return False
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,45 @@


fund_data = [
('TSM', '874039100', 'Taiwan Semiconductor Mfg LTD'),
('VISA', '92826C839', 'Visa Inc'),
("TSM", "874039100", "Taiwan Semiconductor Mfg LTD"),
("VISA", "92826C839", "Visa Inc"),
]

# list of money_market accounts. These will not be held at cost, and instead will use price conversions
money_market = ['VMFXX']
money_market = ["VMFXX"]

fund_info = {
'fund_data': fund_data,
'money_market': money_market,
}
"fund_data": fund_data,
"money_market": money_market,
}


def build_config():
acct = "Assets:Investments:Etrade"
root = 'Investments'
taxability = 'Taxable'
leaf = 'Etrade'
currency = 'USD'
root = "Investments"
taxability = "Taxable"
leaf = "Etrade"
currency = "USD"
config = {
'account_number' : '555555555',
'main_account' : acct + ':{ticker}',
'cash_account' : f'{acct}:{{currency}}',
'transfer' : 'Assets:Zero-Sum-Accounts:Transfers:Bank-Account',
'dividends' : f'Income:{root}:{taxability}:Dividends:{leaf}:{{ticker}}',
'interest' : f'Income:{root}:{taxability}:Interest:{leaf}:{{ticker}}',
'cg' : f'Income:{root}:{taxability}:Capital-Gains:{leaf}:{{ticker}}',
'capgainsd_lt' : f'Income:{root}:{taxability}:Capital-Gains-Distributions:Long:{leaf}:{{ticker}}',
'capgainsd_st' : f'Income:{root}:{taxability}:Capital-Gains-Distributions:Short:{leaf}:{{ticker}}',
'fees' : f'Expenses:Fees-and-Charges:Brokerage-Fees:{taxability}:{leaf}',
'invexpense' : f'Expenses:Expenses:Investment-Expenses:{taxability}:{leaf}',
'rounding_error' : 'Equity:Rounding-Errors:Imports',
'fund_info' : fund_info,
'currency' : currency,
"account_number": "555555555",
"main_account": acct + ":{ticker}",
"cash_account": f"{acct}:{{currency}}",
"transfer": "Assets:Zero-Sum-Accounts:Transfers:Bank-Account",
"dividends": f"Income:{root}:{taxability}:Dividends:{leaf}:{{ticker}}",
"interest": f"Income:{root}:{taxability}:Interest:{leaf}:{{ticker}}",
"cg": f"Income:{root}:{taxability}:Capital-Gains:{leaf}:{{ticker}}",
"capgainsd_lt": f"Income:{root}:{taxability}:Capital-Gains-Distributions:Long:{leaf}:{{ticker}}",
"capgainsd_st": f"Income:{root}:{taxability}:Capital-Gains-Distributions:Short:{leaf}:{{ticker}}",
"fees": f"Expenses:Fees-and-Charges:Brokerage-Fees:{taxability}:{leaf}",
"invexpense": f"Expenses:Expenses:Investment-Expenses:{taxability}:{leaf}",
"rounding_error": "Equity:Rounding-Errors:Imports",
"fund_info": fund_info,
"currency": currency,
}
return config


@regtest.with_importer(
etrade.Importer(
build_config()
)
)
@regtest.with_importer(etrade.Importer(build_config()))
@regtest.with_testdir(path.dirname(__file__))
class TestEtradeQFX(regtest.ImporterTestBase):
pass
14 changes: 7 additions & 7 deletions beancount_reds_importers/importers/fidelity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@


class Importer(investments.Importer, ofxreader.Importer):
IMPORTER_NAME = 'Fidelity Net Benefits / Fidelity Investments OFX'
IMPORTER_NAME = "Fidelity Net Benefits / Fidelity Investments OFX"

def custom_init(self):
self.max_rounding_error = 0.18
self.filename_pattern_def = '.*fidelity'
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"):
return self.config['transfer']
return self.config["transfer"]
if transaction.memo.startswith("FEES"):
return self.config['fees']
return self.config["fees"]
return None

def get_available_cash(self, settlement_fund_balance=0):
return getattr(self.ofx_account.statement, 'available_cash', None)
return getattr(self.ofx_account.statement, "available_cash", None)
Loading

0 comments on commit facce82

Please sign in to comment.