# Path: pynYNAB/schema/budget.py
# class Payee(Base, BudgetEntity):
#     auto_fill_amount = Column(AmountType)
#     auto_fill_amount_enabled = Column(String)
#     auto_fill_memo = Column(String)
#     auto_fill_memo_enabled = Column(String)
#     auto_fill_subcategory_enabled = Column(String)
#     auto_fill_subcategory_id = Column(ForeignKey('subcategory.id'))
#     auto_fill_subcategory = relationship('SubCategory', foreign_keys=auto_fill_subcategory_id)
#     enabled = Column(Boolean, default=True)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     internal_name = Column(String)
#     name = Column(String)
#     rename_on_import_enabled = Column(String)
# 
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)


import csv
import logging
import os
import sys
from collections import namedtuple
from datetime import datetime
from pynYNAB.ClientFactory import clientfromargs
from pynYNAB.schema.budget import Payee, Transaction
    if 'account' not in args.schema.headers:
        entities_account_id = getaccount(args.account_name).id

    amount = None
    if 'inflow' in args.schema.headers and 'outflow' in args.schema.headers:
        pass
    elif 'amount' in args.schema.headers:
        pass
    else:
        LOG.error('This schema doesn''t provide an amount column or (inflow,outflow) columns')
        exit(-1)

    csvrow = namedtuple('CSVrow', field_names=args.schema.headers)

    imported_date = datetime.now().date()

    LOG.debug('OK starting the import from %s ' % os.path.abspath(args.csv_file))
    with open(args.csv_file, 'r') as inputfile:
        header = []
        for i in range(0, args.schema.nheaders):
            header.append(inputfile.readline())
        for row in csv.reader(inputfile):
            if sys.version[0] == '2':
                row = [cell.decode('utf-8') for cell in row]
            if all(map(lambda x: x.strip() == '', row)):
                continue
            LOG.debug('read line %s' % row)
            result = csvrow(*list(args.schema.convert_row(*row, fail_fast=True)))
            if 'account' in args.schema.headers:
                entities_account_id = getaccount(result.account).id

# Path: pynYNAB/schema/budget.py
# class Payee(Base, BudgetEntity):
#     auto_fill_amount = Column(AmountType)
#     auto_fill_amount_enabled = Column(String)
#     auto_fill_memo = Column(String)
#     auto_fill_memo_enabled = Column(String)
#     auto_fill_subcategory_enabled = Column(String)
#     auto_fill_subcategory_id = Column(ForeignKey('subcategory.id'))
#     auto_fill_subcategory = relationship('SubCategory', foreign_keys=auto_fill_subcategory_id)
#     enabled = Column(Boolean, default=True)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     internal_name = Column(String)
#     name = Column(String)
#     rename_on_import_enabled = Column(String)
# 
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)


# Path: pynYNAB/scripts/csvimport.py
import csv
import logging
import os
import sys
from collections import namedtuple
from datetime import datetime
from pynYNAB.ClientFactory import clientfromargs
from pynYNAB.schema.budget import Payee, Transaction

    if 'account' not in args.schema.headers:
        entities_account_id = getaccount(args.account_name).id

    amount = None
    if 'inflow' in args.schema.headers and 'outflow' in args.schema.headers:
        pass
    elif 'amount' in args.schema.headers:
        pass
    else:
        LOG.error('This schema doesn''t provide an amount column or (inflow,outflow) columns')
        exit(-1)

    csvrow = namedtuple('CSVrow', field_names=args.schema.headers)

    imported_date = datetime.now().date()

    LOG.debug('OK starting the import from %s ' % os.path.abspath(args.csv_file))
    with open(args.csv_file, 'r') as inputfile:
        header = []
        for i in range(0, args.schema.nheaders):
            header.append(inputfile.readline())
        for row in csv.reader(inputfile):
            if sys.version[0] == '2':
                row = [cell.decode('utf-8') for cell in row]
            if all(map(lambda x: x.strip() == '', row)):
                continue
            LOG.debug('read line %s' % row)
            result = csvrow(*list(args.schema.convert_row(*row, fail_fast=True)))
            if 'account' in args.schema.headers:
                entities_account_id = getaccount(result.account).id

            if entities_account_id is None: