def testParseMultiAccountFile(self): with open(filename_multi) as f: QifParser.MONTH_IS_BEFORE_DAY_IN_DATES = True qif = QifParser.parse(f) self.assertEqual(2, len(qif.get_accounts())) self.assertEqual('City Checking', qif.get_accounts()[0].name) self.assertEqual('Bank', qif.get_accounts()[0].account_type) self.assertEqual('Global Credit Card', qif.get_accounts()[1].name) self.assertEqual('CCard', qif.get_accounts()[1].account_type) city_account_list = qif.get_accounts(name='City Checking') self.assertEqual(1, len(city_account_list)) city_transactions = city_account_list[0].get_transactions()[0] self.assertEqual(2, len(city_transactions)) self.assert_transaction(city_transactions[0], self.to_datetime('2003-03-27'), Decimal('0.00'), 'X', 'Opening Balance', to_account='City Checking') self.assert_transaction(city_transactions[1], self.to_datetime('1992-01-02'), Decimal('123.45'), 'X', 'Deposit', category='Salary') credit_card_account_list = qif.get_accounts(name='Global Credit Card') self.assertEqual(1, len(credit_card_account_list)) credit_transactions = credit_card_account_list[0].get_transactions()[0] self.assertEqual(3, len(credit_transactions)) self.assert_transaction(credit_transactions[0], self.to_datetime('2015-06-17'), Decimal('0.00'), 'X', 'Opening Balance', to_account='Global Credit Card') self.assert_transaction(credit_transactions[1], self.to_datetime('2015-06-18'), Decimal('-1234.56'), '*', 'Local Store', category='Food') self.assert_transaction(credit_transactions[2], self.to_datetime('2015-06-19'), Decimal('1234.56'), '*', 'Local Store', category='Food')
def testParseTransactionsFile(self): data = open(filename2).read() qif = QifParser.parse(open(filename2)) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEquals(data, str(qif))
def testWriteFile(self): with open(filename) as fh: data = fh.read() with open(filename) as fh: qif = QifParser.parse(fh, date_format='dmy') # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEqual(data, str(qif))
def testWriteFile(self): with open(filename) as f: data = f.read() with open(filename) as ff: qif = QifParser.parse(ff) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEqual(data, str(qif))
def testParseNumberFormat(self): for file_number in range(1,4): with open(build_data_path('number_format_{0:02d}.qif'.format(file_number))) as fh: try: qif = QifParser.parse(fh, date_format='dmy') except QifParserInvalidNumber as err: raise QifParserInvalidNumber("%s in file %s" % (err, fh.name)) transaction = qif.get_transactions()[0][0] self.assertEqual(transaction.amount, Decimal('-1234.56'))
def testParseTransactionsFile(self): with open(self.transactionsfile) as f: data = f.read() f.seek(0) qif = QifParser.parse(f) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEquals(data, str(qif))
def testParseTransactionsFile(self): with open(filename3) as fh: data = fh.read() with open(filename3) as fh: qif = QifParser.parse(fh) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEqual(data, str(qif))
def testParseDateFormat(self): for file_number in range(1, 9): with open( build_data_path( 'date_format_{0:02d}.qif'.format(file_number))) as fh: qif = QifParser.parse(fh, num_sep=('.', '')) transaction = qif.get_transactions()[0][0] self.assertEqual(transaction.date, datetime.datetime(2016, 1, 2))
def testWriteFile(self): for filename in self.standardFiles: with open(filename) as f: data = f.read() f.seek(0) qif = QifParser.parse(f) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEquals(data, str(qif))
def testParseTransactionsFile(self): with open(filename2) as f: data = f.read() with open(filename2) as f: QifParser.MONTH_IS_BEFORE_DAY_IN_DATES = False qif = QifParser.parse(f) # out = open('out.qif', 'w') # out.write(str(qif)) # out.close() self.assertEqual(data, str(qif))
def main(): filename = environ.get('QIFPATH') if not filename: print("No filename set in environment variable QIFPATH") return with open(filename, 'rU') as f: qif = QifParser.parse(f) transactions = qif.get_transactions()[0] raw_amounts = map(lambda x: x.amount, transactions) amounts = filter(lambda x: x, raw_amounts) # cleanup None amounts total = reduce(lambda x, y: x + y, amounts, Decimal(0)) print("Total: ${0}".format(total))
def process_qif_file(config, qif_file, txn_filter): """ Given a QIF file and configuration for splitting transactions, loop through all of the transactions and split them up based on the given configuration. Args: config (dictionary): Split configuration. qif_file (string): Path to a QIF file. txn_filter (dictionary): A collection of rules for filtering transactions. """ with open(qif_file) as q: qif = QifParser.parse(q) for account in qif.get_accounts(): for transactions in account.get_transactions(): for transaction in transactions: if transaction_filter(transaction, txn_filter): splits = get_splits_for_transaction( config, transaction) if splits: process_transaction_splits(splits, transaction) print(str(qif))
def testParseCrLfFile(self): with open(filename2) as fh: qif = QifParser.parse(fh, date_format='dmy') self._check(qif)
def testParseFile(self): with open(filename) as f: QifParser.MONTH_IS_BEFORE_DAY_IN_DATES = False qif = QifParser.parse(f) self.assertTrue(qif)
Securities = [] argParse = argparse.ArgumentParser(description='Generate security holding statement') argParse.add_argument("qiffile", help='the transcation file(.qif) file',\ nargs='?',type=argparse.FileType('r'),default=sys.stdin) argParse.add_argument("outfile",help="the output file",\ nargs='?', type=argparse.FileType('w'),default=sys.stdout) argParse.add_argument("-y", help="only output this year",type=int) argParse.add_argument("-a", nargs='?',type=bool, const=True,\ help="view all sold out secrities in the statment") argParse.add_argument("-S","--sum", nargs='?',type=bool, const=True, \ help="sum total cost at the end of each statment") args = argParse.parse_args() qif = QifParser.parse(args.qiffile) whichyear = args.y viewall = args.a viewsum = args.sum statements = Statements(s_type = 'yearly') for ac in qif.get_accounts(): for trs in ac._transactions.values(): for tr in trs: if tr.action == None: continue action = tr.action.upper() if action == 'BUY' or \
def QifFile(filename): qif = QifParser.parse(open(filename)) for trans_group in qif.get_transactions(): for transaction in trans_group: data = trans_to_dict(transaction) yield data
from qifparse.parser import QifParser # install the patched version: # pip install ../qifparse/dist/qifparser-0.7.tar.gz # Which is from here: https://github.com/el-abcd/qifparse # and built with "python setup.py sdist" filename = '/Users/elee/temp/QDATA_20061105_lineEndFix.QIF' with open(filename) as f: print(f.readline()) qif = QifParser.parse(file(filename)) a = qif.get_accounts() #(<qifparse.qif.Account object at 0x16148d0>, <qifparse.qif.Account object at 0x1614850>) #qif.accounts[0].name #'My Cash' b = qif.get_categories() #(<qifparse.qif.Category object at 0x15b3d10>, <qifparse.qif.Category object at 0x15b3450>) #qif.accounts[0].get_transactions() c = qif.get_transactions() #(<Transaction units=-6.5>, <Transaction units=-6.0>) str(qif) c2 = 0 for cnt, i in enumerate(c[0]): if 'm_LV_7216Buglehorn_Rms-PHH_1108' in i.payee: print(i.payee) print("################### {}".format(c2)) c2 += 1 print(i)
def testParseFile(self): qif = QifParser.parse(open(filename)) self.assertTrue(qif)
def testParseFile(self): with open(filename) as f: qif = QifParser.parse(f) self.assertTrue(qif)
def testAccountList(self): with open(filename_accts) as f: qif = QifParser.parse(f)
def testSecurities(self): with open(filename_security) as f: qif = QifParser.parse(f)
def testParseDateFormat(self): for file_number in range(1,9): with open(build_data_path('date_format_{0:02d}.qif'.format(file_number))) as fh: qif = QifParser.parse(fh, num_sep=('.', '')) transaction = qif.get_transactions()[0][0] self.assertEqual(transaction.date, datetime.datetime(2016, 1, 2))
import sys from os.path import dirname sys.path.append(dirname(__file__)) from qifparse.parser import QifParser from alpha_vantage.timeseries import TimeSeries import time ts = TimeSeries(key='5I186NCN3TF27H5P', output_format='csv') file = open('QuickenExport.QIF') qif = QifParser.parse(file) print("Parsed it ...") quotes = set() for price in qif.get_prices(): quotes.add(price.name) print(quotes) newquotes = {} outstring = "" for quote in quotes: data, meta_data = ts.get_quote_endpoint(quote) data = list(data) if len(data) == 2: price = float(list(data)[1][4]) #print(quote) outstring += "%s, %.3f\n" % (quote, price) # unpayed acces to apha vantage needs 12 seconds between every parse time.sleep(12)