Hello,
Thanks for helping.
I left out code that I thought was unimportant.
My class does have a name function that returns the name of the importer.
So I am not sure why importer.name() is failing.

My class is actually this:

from decimal import Decimal
from os import path
import logging
import csv
import re
from beancount.core import data
from beancount.core.amount import Amount
from dateutil.parser import parse

from beancount.ingest import importer


class ChaseBankImporter(importer.ImporterProtocol):
def __init__(self, account, name, currency='USD'):
self.account = account
self.name = name
self.currency = currency

print(f'account = {self.account} name = {self.name}')

def name(self):
"""Name of this importer"""
return "ChaseBankImporter"

def file_name(self, file):
return path.basename(file.name)

def file_account(self, _):
return self.account

def identify(self, file):
# check file naming convention
return re.match(self.name, path.basename(file.name)) and\
re.match("Details,Posting Date,Description,Amount,Type,Balance,Check or 
Slip #",
file.head())

def get_post_info(self, row):
"""Decipher row description and return a tuple with posting info"""
txn_type = '?'
payee = 'Payee'
description = row['Description']
offset_acct = 'Expenses'

if ';' in description:
items = description.split(';')
payee = items[0]
description = items[1]

if description.startswith('APPLECARD'):
return tuple(['*', 'AppleCard', 'AppleCard Payment', 
'Liabilities:AppleCard'])

if payee.startswith('Football Pool Payout'):
return tuple(['*', payee, description, 'Assets:Football-Pool'])

if 'teterborobowl' in description:
return tuple(['*', 'Bowling', 'Bowling', 'Expenses:Recreation:Bowling'])

if 'CHECK DEPOSIT 12/27' in description:
return tuple(['*', 'Gift Reimburse', 'Gift Reimburse', 
'Expenses:GiftGiven:Other'])

if payee == 'House Repair':
return tuple(['*', payee, description, 'Expenses:House:Repair'])

if description.startswith('ATM WITHDRAWAL'):
return tuple(['*', 'Transfer to Cash', 'ATM Withdrawal', 'Assets:Cash'])

if 'NEW JERSEY NATURAL GAS' in description:
return tuple(['*', 'NJNG', 'NJNG Payment', 'Expenses:Utilities:Gas'])

if 'FIRST ENERGY' in description:
return tuple(['*', 'JCPL', 'JCPL Payment', 'Expenses:Utilities:Electric'])

if description.startswith('VANGUARD SELL'):
return tuple(['*', 'Vanguard Deposit', 'Transfer from Vanguard', 
'Assets:Vanguard'])

if payee == 'Football Pool Deposit':
return tuple(['*', payee, description, 'Assets:Football-Pool'])

if 'CABLEVISION' in description:
return tuple(['*', 'Cablevision', 'Cablevision Payment', 
'Expenses:Utilities:Cable'])

if 'VERIZON' in description:
return tuple(['*', 'Verizon', 'Verizon Payment', 
'Expenses:Utilities:Cellphone'])

if payee == 'Landscaper':
return tuple(['*', payee, description, 'Expenses:House:Landscaping'])

if payee == 'Concert Tix':
return tuple(['*', payee, description, 'Expenses:Recreation:Concerts'])

return tuple([txn_type, payee, description, offset_acct])

def extract(self, file):
"""Process the CSV file and create beancount entries"""
entries = []
index = 0
unknown_count = 0

with open(file.name) as fd:
for index, row in enumerate(csv.DictReader(fd)):
meta = data.new_metadata(file.name, index)
date = parse(row['Posting Date']).date()

post_info = self.get_post_info(row)
if post_info[0] == '?':
unknown_count += 1

amount = Amount(Decimal(row['Amount']), self.currency)
balance = Amount(Decimal(row['Balance']), self.currency)

postings = [
data.Posting(self.account, amount, None, None, None, None),
data.Posting(post_info[3], -amount, None, None, None, None)
]

entries.append(
data.Transaction(
meta,
date,
post_info[0],
post_info[1],
post_info[2],
data.EMPTY_SET,
data.EMPTY_SET,
postings,
)
)

index += 1

if unknown_count > 0:
logging.warning(f'*** THERE WERE {unknown_count} UNKNOWN TRANSACTIONS')

if index > 0:
meta = data.new_metadata(file.name, index-1)
entries.append(
data.Balance(
meta,
date,
self.account,
balance,
None,
None,
)
)

return entries

On Friday, September 2, 2022 at 1:22:15 PM UTC-4 [email protected] wrote:

> On 02/09/2022 16:52, Bruce Berkowicz wrote:
> > Hello, I have just begun attempting to use beancount (v2). I have 
> > written an importer.
> > bean-extract works (thankfully) but bean-identify (and bean-file) throw 
> > an error that I cannot figure out.
>
> >     logfile.write('Importer:    {}\n'.format(importer.name() if 
> > importer else '-'))
> > TypeError: 'str' object is not callable
>
> The Beancount Importer interface requires name() to be a method 
> returning a string. Your importer defines name as a (class or instance) 
> attribute of type str.
>
> > When I run
> > 
> > python3 -m beancount.scripts.deps
> > 
> > there is no output.
>
> This is unusual but unrelated to the problem above.
>
> Cheers,
> Dan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/4f231b22-83f3-4a3d-8d1a-f3dd39496354n%40googlegroups.com.

Reply via email to