|
7 | 7 | from labonneboite.importer import settings as importer_settings |
8 | 8 | from labonneboite.importer.jobs.common import logger |
9 | 9 |
|
| 10 | + |
| 11 | +class NoDataException(Exception): |
| 12 | + pass |
| 13 | + |
10 | 14 | def sql_queries(): |
11 | 15 | create_table_query1 = 'CREATE TABLE IF NOT EXISTS `idpe_connect` ( \ |
12 | 16 | `idutilisateur_peconnect` text, \ |
@@ -56,14 +60,21 @@ def get_dateheure(row): |
56 | 60 |
|
57 | 61 | logger.info('.json files found : {}'.format(json_logs_paths)) |
58 | 62 |
|
| 63 | + file_used = False |
| 64 | + |
59 | 65 | for json_logs_path in json_logs_paths: |
60 | 66 | date = json_logs_path.replace('activity-lbb-','').replace('.json','').replace('.','-') |
61 | 67 | if date >= date_last_recorded_activity: |
| 68 | + file_used = True |
62 | 69 | logger.info('.json file used : {}'.format(json_logs_path)) |
63 | 70 | with open(json_logs_folder_path+'/'+json_logs_path, 'r') as json_file: |
64 | 71 | for line in json_file: |
65 | 72 | data.append(line) |
66 | 73 |
|
| 74 | + if not file_used: |
| 75 | + logger.info("Did not find/need any data to parse") |
| 76 | + raise NoDataException |
| 77 | + |
67 | 78 | activities = {} |
68 | 79 | i = 1 |
69 | 80 | for activity in data: |
@@ -97,6 +108,9 @@ def insert_id_peconnect(activity_df): |
97 | 108 |
|
98 | 109 | engine = import_util.create_sqlalchemy_engine() |
99 | 110 |
|
| 111 | + nb_lines = activity_idpec.shape[0] |
| 112 | + logger.info('Number of lines to insert into idpec : {}'.format(nb_lines)) |
| 113 | + |
100 | 114 | activity_idpec.to_sql( |
101 | 115 | con=engine, name='idpe_connect', if_exists='append', index=False, chunksize=10000) |
102 | 116 |
|
@@ -124,6 +138,9 @@ def siret(row): |
124 | 138 |
|
125 | 139 | engine = import_util.create_sqlalchemy_engine() |
126 | 140 |
|
| 141 | + nb_lines = activity_logs_df.shape[0] |
| 142 | + logger.info('Number of lines to insert into idpec : {}'.format(nb_lines)) |
| 143 | + |
127 | 144 | activity_logs_df.to_sql(con=engine, name='activity_logs', |
128 | 145 | if_exists='append', index=False, chunksize=10000) |
129 | 146 |
|
|
0 commit comments