Mercurial > public > finance-parser
comparison upload_document/app.py @ 11:d09dee7a86da
fix KeyError bug
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 08 Jun 2023 17:35:26 +0100 |
parents | 2350662483a3 |
children | d4c4cd4760fa |
comparison
equal
deleted
inserted
replaced
10:2350662483a3 | 11:d09dee7a86da |
---|---|
48 | 48 |
49 if 'COLUMN_HEADER' in column_types and date == account_value: | 49 if 'COLUMN_HEADER' in column_types and date == account_value: |
50 account_value = '' | 50 account_value = '' |
51 | 51 |
52 with table.batch_writer() as batch: | 52 with table.batch_writer() as batch: |
53 try: | |
54 account_name = account['1'] | |
53 | 55 |
54 # pk -> item_type#company_ticker | 56 # pk -> item_type#company_ticker |
55 # sk -> date#row_index | 57 # sk -> date#row_index |
56 | 58 |
57 batch.put_item( | 59 batch.put_item( |
58 Item={ | 60 Item={ |
59 'pk': f"balance#{event_msg['companyTicker']}", | 61 'pk': f"balance#{event_msg['companyTicker']}", |
60 'sk': f'{date}#{row_index}', | 62 'sk': f'{date}#{row_index}', |
61 'account_name': account['1'], | 63 'account_name': account_name, |
62 'account_value': account_value, | 64 'account_value': account_value, |
63 'column_types': column_types, | 65 'column_types': column_types, |
64 'format': doc['format'] | 66 'format': doc['format'] |
65 } | 67 } |
66 ) | 68 ) |
69 except KeyError: | |
70 pass | |
67 | 71 |
68 # pk -> item_type#company_ticker | 72 # pk -> item_type#company_ticker |
69 # sk -> date#filename | 73 # sk -> date#filename |
70 | 74 |
71 table.put_item( | 75 table.put_item( |
72 Item={ | 76 Item={ |
73 'pk': f"file#balance#{event_msg['companyTicker']}", | 77 'pk': f"file#{event_msg['docType']}#{event_msg['companyTicker']}", |
74 'sk': f"{date}#{event_msg['objectKey'].replace('processed/', '')}" | 78 'sk': f"{date}#{event_msg['objectKey'].replace('processed/', '')}" |
75 } | 79 } |
76 ) | 80 ) |
77 | 81 |
78 return { | 82 return { |