|
9 | 9 |
|
10 | 10 | config = configparser.ConfigParser() |
11 | 11 |
|
| 12 | + # Check if config file exists |
12 | 13 | if not os.path.exists(CONFIG_FILE): |
13 | 14 |
|
14 | | - # INIT CONFIG FIRST TIME (CREATE IT) |
| 15 | + # First time : init config file |
15 | 16 | config.add_section(SETTINGS_SECTION) |
16 | 17 | config.set(SETTINGS_SECTION, IMPORT_ACCOUNT_ID_LIST_FIELD, IMPORT_ACCOUNT_ID_LIST_DEFAULT) |
17 | 18 | config.set(SETTINGS_SECTION, GET_TRANSACTIONS_PERIOD_DAYS_FIELD, GET_TRANSACTIONS_PERIOD_DAYS_DEFAULT) |
|
36 | 37 | file.close() |
37 | 38 |
|
38 | 39 | 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") |
40 | 41 |
|
41 | 42 | else: |
42 | 43 |
|
43 | | - # INIT CONFIG |
| 44 | + # Read config and init sections |
44 | 45 | config.read(CONFIG_FILE) |
45 | 46 | settings_section = config[SETTINGS_SECTION] |
46 | 47 | user_account_section = config[CREDENTIALS_SECTION] |
|
51 | 52 | aa_account_section = config[AA_ACCOUNT_SECTION] |
52 | 53 | aa_tags_section = config[AA_TAGS_SECTION] |
53 | 54 |
|
54 | | - # INIT CREDIT AGRICOLE |
| 55 | + # Init CreditAgricole instance |
55 | 56 | ca_cli = CreditAgricoleClient() |
56 | 57 | ca_cli.region = str(user_account_section.get(BANK_REGION_FIELD, BANK_REGION_DEFAULT)) |
57 | 58 | ca_cli.account_id = str(user_account_section.get(BANK_ACCOUNT_ID_FIELD, BANK_ACCOUNT_ID_DEFAULT)) |
|
62 | 63 | ca_cli.validate() |
63 | 64 | ca_cli.init_session() |
64 | 65 |
|
65 | | - # INIT FIREFLY3 |
| 66 | + # Init Firefly3 instance |
66 | 67 | f3_cli = Firefly3Client() |
67 | 68 | f3_cli.name_format = str(firefly3_section.get(ACCOUNTS_NAME_FORMAT_FIELD, ACCOUNTS_NAME_FORMAT_DEFAULT)) |
68 | 69 | f3_cli.hostname = str(firefly3_section.get(HOSTNAME_FIELD, HOSTNAME_DEFAULT)) |
69 | 70 | f3_cli.token = str(firefly3_section.get(PERSONAL_TOKEN_FIELD, PERSONAL_TOKEN_DEFAULT)) |
70 | 71 | f3_cli.init_auto_assign_values(a_rename_transaction_section, aa_budget_section, aa_category_section, aa_account_section, aa_tags_section) |
71 | 72 | f3_cli.validate() |
72 | 73 |
|
| 74 | + # Start main process |
73 | 75 | print("Process started") |
| 76 | + |
| 77 | + # Get Firefly3 accounts numbers |
74 | 78 | f3_accounts = f3_cli.get_accounts(account_type="asset") |
75 | 79 | 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 |
76 | 82 | for account in ca_cli.get_accounts(): |
| 83 | + |
77 | 84 | name = account.account['libelleProduit'] |
78 | 85 | print("-> '" + name + "' account n°" + account.numeroCompte) |
79 | 86 |
|
80 | | - # CREATE ACCOUNT IF NOT EXISTS |
| 87 | + # Check if CreditAgricole account is already on Firefly3 |
81 | 88 | if account.numeroCompte not in f3_accounts_number: |
82 | 89 |
|
83 | 90 | print(" -> Creating account ... ", end='') |
84 | 91 | if account.grandeFamilleCode == "7": |
| 92 | + # 7 is generally for investment accounts |
85 | 93 | print("Not an asset account!") |
86 | 94 | continue |
87 | 95 |
|
|
90 | 98 | else: |
91 | 99 | account_id = f3_cli.get_account_id(account.numeroCompte) |
92 | 100 |
|
93 | | - # GET TRANSACTIONS |
94 | 101 | print(" -> Retrieving transactions ", end='') |
95 | 102 |
|
| 103 | + # Init a new set of transactions for Firefly3 |
96 | 104 | transactions = Firefly3Transactions(f3_cli) |
| 105 | + |
| 106 | + # Loop through CreditAgricole transactions |
97 | 107 | for ca_transaction in ca_cli.get_transactions(account.numeroCompte): |
98 | 108 | transactions.add_transaction(ca_transaction, account_id) |
99 | 109 | print(".", end='') |
|
102 | 112 |
|
103 | 113 | if len(transactions) > 0: |
104 | 114 | print(" -> Pushing data to Firefly3 instance ", end='') |
105 | | - |
| 115 | + # Push transactions to Firefly3 |
106 | 116 | transactions.post() |
107 | | - |
108 | 117 | print(" Done!") |
0 commit comments