datamule 1.1.8__py3-none-any.whl → 1.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,604 @@
1
+ from .table import Table
2
+ from warnings import warn
3
+ def safe_get(d, keys, default=None):
4
+ """Safely access nested dictionary keys"""
5
+ current = d
6
+ for key in keys:
7
+ if isinstance(current, dict) and key in current:
8
+ current = current[key]
9
+ else:
10
+ return default
11
+ return current
12
+
13
+ def process_tabular_data(self):
14
+ if self.type in ["3","4","5","3/A","4/A","5/A"]:
15
+ tables = process_ownership(self.data, self.accession)
16
+ elif self.type in ["13F-HR", "13F-HR/A","13F-NT", "13F-NT/A"]:
17
+ tables = process_13fhr(self.data, self.accession)
18
+ elif self.type in ["INFORMATION TABLE"]:
19
+ tables = process_information_table(self.data, self.accession)
20
+ elif self.type in ["SBSEF","SBSEF/A","SBSEF-V","SBSEF-W"]:
21
+ tables = process_sbsef(self.data, self.accession)
22
+ elif self.type in ["SDR","SDR/A","SDR-W","SDR-A"]:
23
+ tables = process_sdr_header_data(self.data, self.accession)
24
+ elif self.type in ["EX-99.C SDR"]:
25
+ tables = process_ex_99c_sdr(self.data, self.accession)
26
+ elif self.type in ["EX-99.A SDR SUMMARY"]:
27
+ tables = process_ex_99a_summary_sdr(self.data, self.accession)
28
+ elif self.type in ["EX-99.G SDR"]:
29
+ tables = process_ex_99g_summary_sdr(self.data, self.accession)
30
+ elif self.type in ["EX-99.I SDR SUMMARY"]:
31
+ tables = process_ex_99i_summary_sdr(self.data, self.accession)
32
+ elif self.type in ["144", "144/A"]:
33
+ tables = process_144(self.data, self.accession)
34
+ elif self.type in ["24F-2NT", "24F-2NT/A"]:
35
+ tables = process_24f2nt(self.data, self.accession)
36
+ elif self.type in ["25-NSE", "25-NSE/A"]:
37
+ tables = process_25nse(self.data, self.accession)
38
+ elif self.type in ["ATS-N", "ATS-N/A"]:
39
+ tables = process_ats(self.data, self.accession)
40
+ # elif self.type in ["C","C-W","C-U","C-U-W","C/A","C/A-W",
41
+ # "C-AR","C-AR-W","C-AR/A","C-AR/A-W","C-TR","C-TR-W"]:
42
+ # tables = process_c(self.data, self.accession)
43
+ elif self.type in ["CFPORTAL","CFPORTAL/A","CFPORTAL-W"]:
44
+ tables = process_cfportal(self.data, self.accession)
45
+ # elif self.type in ["D","D/A"]:
46
+ # tables = process_d(self.data, self.accession)
47
+ # elif self.type in ["MA","MA-A","MA/A","MA-I","MA-I/A","MA-W"]:
48
+ # tables = process_ma(self.data, self.accession)
49
+ # elif self.type in ["N-CEN","N-CEN/A"]:
50
+ # tables = process_ncen(self.data, self.accession)
51
+ # elif self.type in ["N-MFP","N-MFP/A","N-MFP1","N-MFP1/A",
52
+ # "N-MFP2","N-MFP2/A","N-MFP3","N-MFP3/A"]:
53
+ # tables = process_nmfp(self.data, self.accession)
54
+ # elif self.type in ["NPORT-P","NPORT-P/A"]:
55
+ # tables = process_nportp(self.data, self.accession)
56
+ elif self.type in ["N-PX","N-PX/A"]:
57
+ tables = process_npx(self.data, self.accession)
58
+ # elif self.type in ["TA-1","TA-1/A","TA-W","TA-2","TA-2/A"]:
59
+ # tables = process_ta(self.data, self.accession)
60
+ elif self.type in ["X-17A-5","X-17A-5/A"]:
61
+ tables = process_x17a5(self.data, self.accession)
62
+ elif self.type in ["SCHEDULE 13D","SCHEDULE 13D/A",
63
+ "SCHEDULE 13G","SCHEDULE 13G/A"]:
64
+ tables = process_schedule_13(self.data, self.accession)
65
+ elif self.type in ["1-A","1-A/A","1-A POS","1-K","1-K/A","1-Z","1-Z/A"]:
66
+ tables = process_reg_a(self.data, self.accession)
67
+ # elif self.type in ["SBSE","SBSE/A","SBSE-A","SBSE-A/A","SBSE-BD","SBSE-BD/A","SBSE-C","SBSE-W","SBSE-CCO-RPT","SBSE-CCO-RPT/A"]:
68
+ # tables = process_sbs(self.data, self.accession)
69
+ # elif self.type in ["EX-102"]:
70
+ # tables = process_ex102_abs(self.data, self.accession)
71
+ elif self.type == "PROXY VOTING RECORD":
72
+ tables = process_proxy_voting_record(self.data, self.accession)
73
+ else:
74
+ warn(f"Processing for {self.type} is not implemented yet.")
75
+ return []
76
+
77
+ if tables is not None:
78
+ [table.map_data() for table in tables]
79
+
80
+ return tables
81
+
82
+ def _flatten_dict(d, parent_key=''):
83
+ items = {}
84
+
85
+ if isinstance(d, list):
86
+ return [_flatten_dict(item) for item in d]
87
+
88
+ for k, v in d.items():
89
+ new_key = f"{parent_key}_{k}" if parent_key else k
90
+
91
+ if isinstance(v, dict):
92
+ items.update(_flatten_dict(v, new_key))
93
+ else:
94
+ items[new_key] = str(v)
95
+
96
+ return items
97
+
98
+ def process_ownership(data, accession):
99
+ tables = []
100
+ if 'ownershipDocument' not in data:
101
+ return tables
102
+
103
+ ownership_doc = data['ownershipDocument']
104
+
105
+ if 'nonDerivativeTable' in ownership_doc:
106
+ non_deriv_table = ownership_doc['nonDerivativeTable']
107
+ if 'nonDerivativeHolding' in non_deriv_table and non_deriv_table['nonDerivativeHolding']:
108
+ tables.append(Table(_flatten_dict(non_deriv_table['nonDerivativeHolding']), 'non_derivative_holding_ownership', accession))
109
+ if 'nonDerivativeTransaction' in non_deriv_table and non_deriv_table['nonDerivativeTransaction']:
110
+ tables.append(Table(_flatten_dict(non_deriv_table['nonDerivativeTransaction']), 'non_derivative_transaction_ownership', accession))
111
+
112
+ if 'derivativeTable' in ownership_doc:
113
+ deriv_table = ownership_doc['derivativeTable']
114
+ if 'derivativeHolding' in deriv_table and deriv_table['derivativeHolding']:
115
+ tables.append(Table(_flatten_dict(deriv_table['derivativeHolding']), 'derivative_holding_ownership', accession))
116
+ if 'derivativeTransaction' in deriv_table and deriv_table['derivativeTransaction']:
117
+ tables.append(Table(_flatten_dict(deriv_table['derivativeTransaction']), 'derivative_transaction_ownership', accession))
118
+
119
+ metadata_table_dict = {'schemaVersion': ownership_doc.get('schemaVersion', None),
120
+ 'documentType': ownership_doc.get('documentType', None),
121
+ 'periodOfReport': ownership_doc.get('periodOfReport', None),
122
+ 'dateOfOriginalSubmission': ownership_doc.get('dateOfOriginalSubmission', None),
123
+ 'noSecuritiesOwned': ownership_doc.get('noSecuritiesOwned', None),
124
+ 'notSubjectToSection16': ownership_doc.get('notSubjectToSection16', None),
125
+ 'form3HoldingsReported': ownership_doc.get('form3HoldingsReported', None),
126
+ 'form4TransactionsReported': ownership_doc.get('form4TransactionsReported', None),
127
+ 'aff10b5One': ownership_doc.get('aff10b5One', None),
128
+ 'remarks': ownership_doc.get('remarks', None)}
129
+
130
+ metadata_table = Table(data=metadata_table_dict, type='metadata_ownership', accession=accession)
131
+ tables.append(metadata_table)
132
+
133
+ if 'reportingOwner' in ownership_doc:
134
+ tables.append(Table(_flatten_dict(ownership_doc['reportingOwner']), 'reporting_owner_ownership', accession))
135
+
136
+ if 'ownerSignature' in ownership_doc:
137
+ tables.append(Table(_flatten_dict(ownership_doc['ownerSignature']), 'owner_signature_ownership', accession))
138
+
139
+ return tables
140
+
141
+ def process_information_table(data, accession):
142
+ tables = []
143
+ information_table = safe_get(data, ['informationTable','infoTable'])
144
+ if information_table:
145
+ tables.append(Table(_flatten_dict(information_table), 'information_table', accession))
146
+ return tables
147
+
148
+ def process_13fhr(data, accession):
149
+ tables = []
150
+ edgar_submission = safe_get(data, ['edgarSubmission'])
151
+ if edgar_submission:
152
+ tables.append(Table(_flatten_dict(edgar_submission), '13fhr', accession))
153
+ return tables
154
+
155
+ def process_sbsef(data, accession):
156
+ tables = []
157
+ header_data = safe_get(data, ['edgarSubmission'])
158
+ if header_data:
159
+ tables.append(Table(_flatten_dict(header_data), 'sbsef', accession))
160
+ return tables
161
+
162
+ def process_sdr_header_data(data, accession):
163
+ tables = []
164
+ edgar_submission = safe_get(data, ['edgarSubmission'])
165
+ if edgar_submission:
166
+ tables.append(Table(_flatten_dict(edgar_submission), 'sdr', accession))
167
+ return tables
168
+
169
+ def process_ex_99c_sdr(data, accession):
170
+ tables = []
171
+ director_governors = safe_get(data, ['directorGovernors','officer'])
172
+ if director_governors:
173
+ tables.append(Table(_flatten_dict(director_governors), 'ex99c_sdr', accession))
174
+ return tables
175
+
176
+ def process_ex_99a_summary_sdr(data, accession):
177
+ tables = []
178
+ controlling_persons = safe_get(data, ['controllingPersons','controlPerson'])
179
+ if controlling_persons:
180
+ tables.append(Table(_flatten_dict(controlling_persons), 'ex99a_sdr', accession))
181
+ return tables
182
+
183
+ def process_ex_99g_summary_sdr(data, accession):
184
+ tables = []
185
+ affiliates = safe_get(data, ['affiliates','affiliate'])
186
+ if affiliates:
187
+ tables.append(Table(_flatten_dict(affiliates), 'ex99g_sdr', accession))
188
+ return tables
189
+
190
+ def process_ex_99i_summary_sdr(data, accession):
191
+ tables = []
192
+ service_provider_contracts = safe_get(data, ['serviceProviderContracts','serviceProviderContract'])
193
+ if service_provider_contracts:
194
+ tables.append(Table(_flatten_dict(service_provider_contracts), 'ex99i_sdr', accession))
195
+ return tables
196
+
197
+ def process_144(data, accession):
198
+ tables = []
199
+ notice_signature = safe_get(data, ['edgarSubmission', 'formData', 'noticeSignature'])
200
+ if notice_signature:
201
+ tables.append(Table(_flatten_dict(notice_signature), 'signatures_144', accession))
202
+
203
+ securities_sold = safe_get(data, ['edgarSubmission', 'formData', 'securitiesSoldInPast3Months'])
204
+ if securities_sold:
205
+ tables.append(Table(_flatten_dict(securities_sold), 'securities_sold_in_past_3_months_144', accession))
206
+
207
+ securities_to_be_sold = safe_get(data, ['edgarSubmission', 'formData', 'securitiesToBeSold'])
208
+ if securities_to_be_sold:
209
+ tables.append(Table(_flatten_dict(securities_to_be_sold), 'securities_to_be_sold_144', accession))
210
+
211
+ securities_info = safe_get(data, ['edgarSubmission', 'formData', 'securitiesInformation'])
212
+ if securities_info:
213
+ tables.append(Table(_flatten_dict(securities_info), 'securities_information_144', accession))
214
+
215
+ issuer_info = safe_get(data, ['edgarSubmission', 'formData', 'issuerInfo'])
216
+ if issuer_info:
217
+ tables.append(Table(_flatten_dict(issuer_info), 'issuer_information_144', accession))
218
+
219
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
220
+ metadata_table = Table(_flatten_dict(header_data), 'metadata_144', accession)
221
+ remarks = safe_get(data, ['edgarSubmission', 'formData', 'remarks'])
222
+ if remarks:
223
+ metadata_table.add_column('remarks', remarks)
224
+
225
+ tables.append(metadata_table)
226
+
227
+ return tables
228
+
229
+ def process_24f2nt(data, accession):
230
+ tables = []
231
+
232
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
233
+ if header_data:
234
+ header_data_table = Table(_flatten_dict(header_data), 'metadata_24f_2nt', accession)
235
+ schema_version = safe_get(data, ['edgarSubmission', 'schemaVersion'])
236
+ if schema_version:
237
+ header_data_table.add_column('schemaVersion', schema_version)
238
+ tables.append(header_data_table)
239
+
240
+ item1 = safe_get(data, ['edgarSubmission', 'formData', 'annualFilings', 'annualFilingInfo', 'item1'])
241
+ if item1:
242
+ tables.append(Table(_flatten_dict(item1), 'item_1_24f2nt', accession))
243
+
244
+ for i in range(2, 10):
245
+ item = safe_get(data, ['edgarSubmission', 'formData', 'annualFilings', 'annualFilingInfo', f'item{i}'])
246
+ if item:
247
+ tables.append(Table(_flatten_dict(item), f'item_{i}_24f2nt', accession))
248
+
249
+ signature = safe_get(data, ['edgarSubmission', 'formData', 'annualFilings', 'annualFilingInfo', 'signature'])
250
+ if signature:
251
+ tables.append(Table(_flatten_dict(signature), 'signature_24f2nt', accession))
252
+
253
+ return tables
254
+
255
+ def process_25nse(data, accession):
256
+ tables = []
257
+ notification = safe_get(data, ['notificationOfRemoval'])
258
+ if notification:
259
+ tables.append(Table(_flatten_dict(notification), '25nse', accession))
260
+ return tables
261
+
262
+ def process_ats(data, accession):
263
+ tables = []
264
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
265
+ if header_data:
266
+ tables.append(Table(_flatten_dict(header_data), 'metadata_ats', accession))
267
+
268
+ cover = safe_get(data, ['edgarSubmission', 'formData', 'cover'])
269
+ if cover:
270
+ tables.append(Table(_flatten_dict(cover), 'cover_ats', accession))
271
+
272
+ part_one = safe_get(data, ['edgarSubmission', 'formData', 'partOne'])
273
+ if part_one:
274
+ tables.append(Table(_flatten_dict(part_one), 'part_one_ats', accession))
275
+
276
+ part_two = safe_get(data, ['edgarSubmission', 'formData', 'partTwo'])
277
+ if part_two:
278
+ tables.append(Table(_flatten_dict(part_two), 'part_two_ats', accession))
279
+
280
+ part_three = safe_get(data, ['edgarSubmission', 'formData', 'partThree'])
281
+ if part_three:
282
+ tables.append(Table(_flatten_dict(part_three), 'part_three_ats', accession))
283
+
284
+ part_four = safe_get(data, ['edgarSubmission', 'formData', 'partFour'])
285
+ if part_four:
286
+ tables.append(Table(_flatten_dict(part_four), 'part_four_ats', accession))
287
+
288
+ return tables
289
+
290
+ # def process_c(data, accession):
291
+ # tables = []
292
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
293
+ # if header_data:
294
+ # tables.append(Table(_flatten_dict(header_data), 'metadata_c', accession))
295
+
296
+ # issuer_info = safe_get(data, ['edgarSubmission', 'formData', 'issuerInformation'])
297
+ # if issuer_info:
298
+ # tables.append(Table(_flatten_dict(issuer_info), 'issuer_information_c', accession))
299
+
300
+ # offering_info = safe_get(data, ['edgarSubmission', 'formData', 'offeringInformation'])
301
+ # if offering_info:
302
+ # tables.append(Table(_flatten_dict(offering_info), 'offering_information_c', accession))
303
+
304
+ # annual_report = safe_get(data, ['edgarSubmission', 'formData', 'annualReportDisclosureRequirements'])
305
+ # if annual_report:
306
+ # tables.append(Table(_flatten_dict(annual_report), 'annual_report_disclosure_requirements_c', accession))
307
+
308
+ # signature_info = safe_get(data, ['edgarSubmission', 'formData', 'signatureInfo'])
309
+ # if signature_info:
310
+ # tables.append(Table(_flatten_dict(signature_info), 'signature_info_c', accession))
311
+
312
+ # return tables
313
+
314
+ def process_cfportal(data, accession):
315
+ tables = []
316
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
317
+ if header_data:
318
+ tables.append(Table(_flatten_dict(header_data), 'metadata_cfportal', accession))
319
+
320
+ base_path = ['edgarSubmission', 'formData']
321
+ sections = [
322
+ ('identifyingInformation', 'identifying_information_cfportal'),
323
+ ('formOfOrganization', 'form_of_organization_cfportal'),
324
+ ('successions', 'successions_cfportal'),
325
+ ('controlRelationships', 'control_relationships_cfportal'),
326
+ ('disclosureAnswers', 'disclosure_answers_cfportal'),
327
+ ('nonSecuritiesRelatedBusiness', 'non_securities_related_business_cfportal'),
328
+ ('escrowArrangements', 'escrow_arrangements_cfportal'),
329
+ ('execution', 'execution_cfportal'),
330
+ ('scheduleA', 'schedule_a_cfportal'),
331
+ ('scheduleB', 'schedule_b_cfportal'),
332
+ ('scheduleC', 'schedule_c_cfportal'),
333
+ ('scheduleD', 'schedule_d_cfportal'),
334
+ ('criminalDrpInfo', 'criminal_drip_info_cfportal'),
335
+ ('regulatoryDrpInfo', 'regulatory_drip_info_cfportal'),
336
+ ('civilJudicialDrpInfo', 'civil_judicial_drip_info_cfportal'),
337
+ ('bankruptcySipcDrpInfo', 'bankruptcy_sipc_drip_info_cfportal'),
338
+ ('bondDrpInfo', 'bond_drip_info_cfportal'),
339
+ ('judgementDrpInfo', 'judgement_drip_info_cfportal')
340
+ ]
341
+
342
+ for section_key, table_name in sections:
343
+ section_data = safe_get(data, base_path + [section_key])
344
+ if section_data:
345
+ tables.append(Table(_flatten_dict(section_data), table_name, accession))
346
+
347
+ return tables
348
+
349
+ # def process_d(data, accession):
350
+ # tables = []
351
+ # primary_issuer = safe_get(data, ['edgarSubmission', 'primaryIssuer'])
352
+ # if primary_issuer:
353
+ # metadata = Table(_flatten_dict(primary_issuer), 'metadata_d', accession)
354
+
355
+ # metadata_columns = ['schemaVersion', 'submissionType', 'testOrLive', 'returnCopy', 'contactData', 'notificationAddressList']
356
+ # for col in metadata_columns:
357
+ # col_data = safe_get(data, ['edgarSubmission', col])
358
+ # if col_data:
359
+ # metadata.add_column(col, col_data)
360
+
361
+ # tables.append(metadata)
362
+
363
+ # issuer_list = safe_get(data, ['edgarSubmission', 'issuerList'])
364
+ # if issuer_list:
365
+ # tables.append(Table(_flatten_dict(issuer_list), 'primary_issuer_d', accession))
366
+
367
+ # offering_data = safe_get(data, ['edgarSubmission', 'offeringData'])
368
+ # if offering_data:
369
+ # tables.append(Table(_flatten_dict(offering_data), 'offering_data_d', accession))
370
+
371
+ # related_persons_list = safe_get(data, ['edgarSubmission', 'relatedPersonsList'])
372
+ # if related_persons_list:
373
+ # tables.append(Table(_flatten_dict(related_persons_list), 'related_persons_list_d', accession))
374
+
375
+ # return tables
376
+
377
+ # def process_nmfp(data, accession):
378
+ # tables = []
379
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
380
+ # if header_data:
381
+ # tables.append(Table(_flatten_dict(header_data), 'metadata_nmfp', accession))
382
+
383
+ # general_info = safe_get(data, ['edgarSubmission', 'formData', 'generalInfo'])
384
+ # if general_info:
385
+ # tables.append(Table(_flatten_dict(general_info), 'general_information_nmfp', accession))
386
+
387
+ # series_level_info = safe_get(data, ['edgarSubmission', 'formData', 'seriesLevelInfo'])
388
+ # if series_level_info:
389
+ # tables.append(Table(_flatten_dict(series_level_info), 'series_level_info_nmfp', accession))
390
+
391
+ # class_level_info = safe_get(data, ['edgarSubmission', 'formData', 'classLevelInfo'])
392
+ # if class_level_info:
393
+ # tables.append(Table(_flatten_dict(class_level_info), 'class_level_info_nmfp', accession))
394
+
395
+ # portfolio_securities = safe_get(data, ['edgarSubmission', 'formData', 'scheduleOfPortfolioSecuritiesInfo'])
396
+ # if portfolio_securities:
397
+ # tables.append(Table(_flatten_dict(portfolio_securities), 'schedule_of_portfolio_securities_info_nmfp', accession))
398
+
399
+ # signature = safe_get(data, ['edgarSubmission', 'formData', 'signature'])
400
+ # if signature:
401
+ # tables.append(Table(_flatten_dict(signature), 'signature_nmfp', accession))
402
+
403
+ # return tables
404
+
405
+ # def process_nportp(data, accession):
406
+ # tables = []
407
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
408
+ # if header_data:
409
+ # tables.append(Table(_flatten_dict(header_data), 'metadata_nportp', accession))
410
+
411
+ # gen_info = safe_get(data, ['edgarSubmission', 'formData', 'genInfo'])
412
+ # if gen_info:
413
+ # tables.append(Table(_flatten_dict(gen_info), 'general_information_nportp', accession))
414
+
415
+ # fund_info = safe_get(data, ['edgarSubmission', 'formData', 'fundInfo'])
416
+ # if fund_info:
417
+ # tables.append(Table(_flatten_dict(fund_info), 'fund_information_nportp', accession))
418
+
419
+ # invst_or_secs = safe_get(data, ['edgarSubmission', 'formData', 'invstOrSecs'])
420
+ # if invst_or_secs:
421
+ # tables.append(Table(_flatten_dict(invst_or_secs), 'investment_or_securities_nportp', accession))
422
+
423
+ # signature = safe_get(data, ['edgarSubmission', 'formData', 'signature'])
424
+ # if signature:
425
+ # tables.append(Table(_flatten_dict(signature), 'signature_nportp', accession))
426
+
427
+ # return tables
428
+
429
+ def process_npx(data, accession):
430
+ tables = []
431
+ edgar_submission = safe_get(data, ['edgarSubmission'])
432
+ if edgar_submission:
433
+ tables.append(Table(_flatten_dict(edgar_submission), 'npx', accession))
434
+ return tables
435
+
436
+ def process_proxy_voting_record(data, accession):
437
+ tables = []
438
+ proxy_table = safe_get(data, ['proxyVoteTable', 'proxyTable'])
439
+ if proxy_table:
440
+ tables.append(Table(_flatten_dict(proxy_table), 'proxy_voting_record', accession))
441
+ return tables
442
+
443
+ # SOMETHING IS VERY OFF HERE
444
+ # def process_ta(data, accession):
445
+ # tables = []
446
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
447
+ # if header_data:
448
+ # metadata_ta = Table(_flatten_dict(header_data), 'metadata_ta', accession)
449
+ # schema_version = safe_get(data, ['edgarSubmission', 'schemaVersion'])
450
+ # if schema_version:
451
+ # metadata_ta.add_column('schemaVersion', schema_version)
452
+ # tables.append(metadata_ta)
453
+
454
+ # registrant = safe_get(data, ['edgarSubmission', 'registrant'])
455
+ # if registrant:
456
+ # tables.append(Table(_flatten_dict(registrant), 'registrant_ta', accession))
457
+
458
+ # independent_registrant = safe_get(data, ['edgarSubmission', 'formData', 'independentRegistrant'])
459
+ # if independent_registrant:
460
+ # tables.append(Table(_flatten_dict(independent_registrant), 'independent_registrant_ta', accession))
461
+
462
+ # disciplinary_history = safe_get(data, ['edgarSubmission', 'formData', 'disciplinaryHistory'])
463
+ # if disciplinary_history:
464
+ # tables.append(Table(_flatten_dict(disciplinary_history), 'disciplinary_history_ta', accession))
465
+
466
+ # signature = safe_get(data, ['edgarSubmission', 'formData', 'signature'])
467
+ # if signature:
468
+ # tables.append(Table(_flatten_dict(signature), 'signature_ta', accession))
469
+
470
+ # return tables
471
+
472
+ def process_x17a5(data, accession):
473
+ tables = []
474
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
475
+ if header_data:
476
+ tables.append(Table(_flatten_dict(header_data), 'metadata_x17a5', accession))
477
+
478
+ submission_info = safe_get(data, ['edgarSubmission', 'formData', 'submissionInformation'])
479
+ if submission_info:
480
+ tables.append(Table(_flatten_dict(submission_info), 'submission_information_x17a5', accession))
481
+
482
+ registrant_id = safe_get(data, ['edgarSubmission', 'formData', 'registrantIdentification'])
483
+ if registrant_id:
484
+ tables.append(Table(_flatten_dict(registrant_id), 'registrant_identification_x17a5', accession))
485
+
486
+ accountant_id = safe_get(data, ['edgarSubmission', 'formData', 'accountantIdentification'])
487
+ if accountant_id:
488
+ tables.append(Table(_flatten_dict(accountant_id), 'accountant_identification_x17a5', accession))
489
+
490
+ oath_signature = safe_get(data, ['edgarSubmission', 'formData', 'oathSignature'])
491
+ if oath_signature:
492
+ tables.append(Table(_flatten_dict(oath_signature), 'oath_signature_x17a5', accession))
493
+
494
+ return tables
495
+
496
+ def process_schedule_13(data, accession):
497
+ tables = []
498
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
499
+ if header_data:
500
+ tables.append(Table(_flatten_dict(header_data), 'metadata_schedule_13', accession))
501
+
502
+ cover_page_header = safe_get(data, ['edgarSubmission', 'formData', 'coverPageHeader'])
503
+ if cover_page_header:
504
+ tables.append(Table(_flatten_dict(cover_page_header), 'cover_schedule_13', accession))
505
+
506
+ cover_page_details = safe_get(data, ['edgarSubmission', 'formData', 'coverPageHeaderReportingPersonDetails'])
507
+ if cover_page_details:
508
+ tables.append(Table(_flatten_dict(cover_page_details), 'reporting_person_details_schedule_13', accession))
509
+
510
+ items = safe_get(data, ['edgarSubmission', 'formData', 'items'])
511
+ if items and isinstance(items, dict):
512
+ for k, v in items.items():
513
+ if v:
514
+ tables.append(Table(_flatten_dict(v), f'{k}_schedule_13', accession))
515
+
516
+ signature_info = safe_get(data, ['edgarSubmission', 'formData', 'signatureInformation'])
517
+ if signature_info:
518
+ tables.append(Table(_flatten_dict(signature_info), 'signature_information_schedule_13', accession))
519
+
520
+ return tables
521
+
522
+ def process_reg_a(data, accession):
523
+ tables = []
524
+ header_data = safe_get(data, ['edgarSubmission', 'headerData'])
525
+ if header_data:
526
+ tables.append(Table(_flatten_dict(header_data), 'metadata_reg_a', accession))
527
+
528
+ base_path = ['edgarSubmission', 'formData']
529
+ sections = [
530
+ ('employeesInfo', 'employees_info_reg_a'),
531
+ ('issuerInfo', 'issuer_info_reg_a'),
532
+ ('commonEquity', 'common_equity_reg_a'),
533
+ ('preferredEquity', 'preferred_equity_reg_a'),
534
+ ('debtSecurities', 'debt_securities_reg_a'),
535
+ ('issuerEligibility', 'issuer_eligibility_reg_a'),
536
+ ('applicationRule262', 'application_rule_262_reg_a'),
537
+ ('summaryInfo', 'summary_info_reg_a'),
538
+ ('juridictionSecuritiesOffered', 'juridiction_securities_offered_reg_a'),
539
+ ('unregisteredSecurities', 'unregistered_securities_reg_a'),
540
+ ('securitiesIssued', 'securities_issued_reg_a'),
541
+ ('unregisteredSecuritiesAct', 'unregistered_securities_act_reg_a')
542
+ ]
543
+
544
+ for section_key, table_name in sections:
545
+ section_data = safe_get(data, base_path + [section_key])
546
+ if section_data:
547
+ tables.append(Table(_flatten_dict(section_data), table_name, accession))
548
+
549
+ return tables
550
+
551
+ # looks good but some extra nesed tables we missed
552
+ # def process_sbs(data, accession):
553
+ # tables = []
554
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
555
+ # if header_data:
556
+ # tables.append(Table(_flatten_dict(header_data), 'metadata_sbse', accession))
557
+
558
+ # applicant = safe_get(data, ['edgarSubmission', 'formData', 'applicant'])
559
+ # if applicant and isinstance(applicant, dict):
560
+ # for k, v in applicant.items():
561
+ # if v:
562
+ # tables.append(Table(_flatten_dict(v), f'applicant_{k}_sbs', accession))
563
+
564
+ # base_path = ['edgarSubmission', 'formData']
565
+ # sections = [
566
+ # ('scheduleA', 'schedule_a_sbs'),
567
+ # ('scheduleB', 'schedule_b_sbs'),
568
+ # ('scheduleC', 'schedule_c_sbs'),
569
+ # ('scheduleD', 'schedule_d_sbs'),
570
+ # ('scheduleE', 'schedule_e_sbs'),
571
+ # ('scheduleF', 'schedule_f_sbs'),
572
+ # ('criminalDrpInfo', 'criminal_drip_info_sbs'),
573
+ # ('regulatoryDrpInfo', 'regulatory_drip_info_sbs'),
574
+ # ('civilJudicialDrpInfo', 'civil_judicial_drip_info_sbs'),
575
+ # ('bankruptcySipcDrpInfo', 'bankruptcy_sipc_drip_info_sbs'),
576
+ # ('execution', 'execution_sbs')
577
+ # ]
578
+
579
+ # for section_key, table_name in sections:
580
+ # section_data = safe_get(data, base_path + [section_key])
581
+ # if section_data:
582
+ # tables.append(Table(_flatten_dict(section_data), table_name, accession))
583
+
584
+ # return tables
585
+
586
+ # def process_ex102_abs(data, accession):
587
+ # tables = []
588
+ # asset_data = safe_get(data, ['assetData'])
589
+ # if asset_data:
590
+ # tables.append(Table(_flatten_dict(asset_data), 'abs', accession))
591
+ # raise NotImplementedError("Need to implement the rest of the ABS processing")
592
+ # return tables
593
+
594
+ # def process_ma(data, accession):
595
+ # tables = []
596
+ # header_data = safe_get(data, ['edgarSubmission', 'headerData'])
597
+ # if header_data:
598
+ # header_ma = Table(_flatten_dict(header_data), 'metadata_ma', accession)
599
+ # tables.append(header_ma)
600
+ # # WE NEED TO COMBINE TABLES
601
+ # raise NotImplementedError("Need to implement the rest of the MA processing")
602
+
603
+ # def process_ncen(data, accession):
604
+ # raise NotImplementedError("Need to implement the N-CEN processing")