51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
import os, codecs, sys
|
|
from transaction import *
|
|
from models.transactions import *
|
|
|
|
#create_tables()
|
|
|
|
# delete csv output files if already exists
|
|
for root, dirs, files in os.walk('output'):
|
|
for file in files:
|
|
if file.endswith(".csv"):
|
|
os.remove(f"{root}/{file}")
|
|
|
|
for root, dirs, files in os.walk('accounts'):
|
|
for file in files:
|
|
file_name = f"{root}/{file}"
|
|
with codecs.open(file_name, 'r', encoding='utf-8-sig') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
# check if transaction already exists in the db which means it has been updated in Firefly 3 already
|
|
transaction = Transactions.get_or_none(Transactions.raw_line.contains(line))
|
|
# transaction = Transactions.select().where(Transactions.raw_line==line.strip())
|
|
if transaction is None:
|
|
|
|
# if does not exist create new transaction
|
|
t = Transactions()
|
|
t.raw_line = line
|
|
t.tag = ""
|
|
|
|
if root == "accounts\\HSBC_ATM_VND":
|
|
t.account_name = Accounts.HSBC_ATM_VND.value
|
|
t.asset_account = Accounts.HSBC_ATM_VND.value
|
|
t.currency = "VND"
|
|
t.account_short_name = Accounts.HSBC_ATM_VND.name
|
|
createTransactionCurrentVND(t)
|
|
elif root == "accounts\\HSBC_CreditCard_VND":
|
|
t.account_name = Accounts.HSBC_CreditCard_VND.value
|
|
t.asset_account = Accounts.HSBC_CreditCard_VND.value
|
|
t.currency = "VND"
|
|
t.account_short_name = Accounts.HSBC_CreditCard_VND.name
|
|
createTransactionCreditCardVND(t)
|
|
elif root == "accounts\\SG_Greg_EUR":
|
|
t.account_name = Accounts.SG_Greg_EUR.value
|
|
t.asset_account = Accounts.SG_Greg_EUR.value
|
|
t.currency = "EUR"
|
|
t.account_short_name = Accounts.SG_Greg_EUR.name
|
|
createTransactionSGEUR(t)
|
|
|
|
else:
|
|
print("This bank account does not exist...")
|
|
|