Skip to content

Commit c53c37e

Browse files
committed
Better comments & wiki link
1 parent 01a281d commit c53c37e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

main.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
config = configparser.ConfigParser()
1111

12+
# Check if config file exists
1213
if not os.path.exists(CONFIG_FILE):
1314

14-
# INIT CONFIG FIRST TIME (CREATE IT)
15+
# First time : init config file
1516
config.add_section(SETTINGS_SECTION)
1617
config.set(SETTINGS_SECTION, IMPORT_ACCOUNT_ID_LIST_FIELD, IMPORT_ACCOUNT_ID_LIST_DEFAULT)
1718
config.set(SETTINGS_SECTION, GET_TRANSACTIONS_PERIOD_DAYS_FIELD, GET_TRANSACTIONS_PERIOD_DAYS_DEFAULT)
@@ -36,11 +37,11 @@
3637
file.close()
3738

3839
print("Config file '" + CONFIG_FILE + "' created ! Please fill it and start this script again.")
39-
print("Wiki page to help you : XXX")
40+
print("Wiki page to help you : https://github.com/Royalphax/credit-agricole-importer/wiki/Config-file")
4041

4142
else:
4243

43-
# INIT CONFIG
44+
# Read config and init sections
4445
config.read(CONFIG_FILE)
4546
settings_section = config[SETTINGS_SECTION]
4647
user_account_section = config[CREDENTIALS_SECTION]
@@ -51,7 +52,7 @@
5152
aa_account_section = config[AA_ACCOUNT_SECTION]
5253
aa_tags_section = config[AA_TAGS_SECTION]
5354

54-
# INIT CREDIT AGRICOLE
55+
# Init CreditAgricole instance
5556
ca_cli = CreditAgricoleClient()
5657
ca_cli.region = str(user_account_section.get(BANK_REGION_FIELD, BANK_REGION_DEFAULT))
5758
ca_cli.account_id = str(user_account_section.get(BANK_ACCOUNT_ID_FIELD, BANK_ACCOUNT_ID_DEFAULT))
@@ -62,26 +63,33 @@
6263
ca_cli.validate()
6364
ca_cli.init_session()
6465

65-
# INIT FIREFLY3
66+
# Init Firefly3 instance
6667
f3_cli = Firefly3Client()
6768
f3_cli.name_format = str(firefly3_section.get(ACCOUNTS_NAME_FORMAT_FIELD, ACCOUNTS_NAME_FORMAT_DEFAULT))
6869
f3_cli.hostname = str(firefly3_section.get(HOSTNAME_FIELD, HOSTNAME_DEFAULT))
6970
f3_cli.token = str(firefly3_section.get(PERSONAL_TOKEN_FIELD, PERSONAL_TOKEN_DEFAULT))
7071
f3_cli.init_auto_assign_values(a_rename_transaction_section, aa_budget_section, aa_category_section, aa_account_section, aa_tags_section)
7172
f3_cli.validate()
7273

74+
# Start main process
7375
print("Process started")
76+
77+
# Get Firefly3 accounts numbers
7478
f3_accounts = f3_cli.get_accounts(account_type="asset")
7579
f3_accounts_number = [account.get("attributes").get("account_number") for account in f3_accounts]
80+
81+
# Loop through existing CreditAgricole accounts declared in config file
7682
for account in ca_cli.get_accounts():
83+
7784
name = account.account['libelleProduit']
7885
print("-> '" + name + "' account n°" + account.numeroCompte)
7986

80-
# CREATE ACCOUNT IF NOT EXISTS
87+
# Check if CreditAgricole account is already on Firefly3
8188
if account.numeroCompte not in f3_accounts_number:
8289

8390
print(" -> Creating account ... ", end='')
8491
if account.grandeFamilleCode == "7":
92+
# 7 is generally for investment accounts
8593
print("Not an asset account!")
8694
continue
8795

@@ -90,10 +98,12 @@
9098
else:
9199
account_id = f3_cli.get_account_id(account.numeroCompte)
92100

93-
# GET TRANSACTIONS
94101
print(" -> Retrieving transactions ", end='')
95102

103+
# Init a new set of transactions for Firefly3
96104
transactions = Firefly3Transactions(f3_cli)
105+
106+
# Loop through CreditAgricole transactions
97107
for ca_transaction in ca_cli.get_transactions(account.numeroCompte):
98108
transactions.add_transaction(ca_transaction, account_id)
99109
print(".", end='')
@@ -102,7 +112,6 @@
102112

103113
if len(transactions) > 0:
104114
print(" -> Pushing data to Firefly3 instance ", end='')
105-
115+
# Push transactions to Firefly3
106116
transactions.post()
107-
108117
print(" Done!")

0 commit comments

Comments
 (0)