Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions postgres/IngestDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ def insert_document(conn, json_data):
attributes.get("topics"),
attributes.get("withdrawn"),
attributes.get("zip"),
attributes.get("frDocNum"),
attributes.get("relationships").get("attachments").get("links").get("self"),
attributes.get("relationships").get("attachments").get("links").get("related"),
attributes.get("fileFormats"),
attributes.get("displayProperties"),
)

# attachments_self_link VARCHAR(2000),
# attachments_related_link VARCHAR(2000),
# file_formats JSONB,
# display_properties JSONB


# Insert into the database
try:
with conn.cursor() as cursor:
Expand All @@ -85,16 +96,16 @@ def insert_document(conn, json_data):
submitter_org, phone, posted_date, postmark_date, reason_withdrawn,
receive_date, reg_writer_instruction, restriction_reason,
restriction_reason_type, state_province_region, subtype,
document_title, topics, is_withdrawn, postal_code
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
document_title, topics, is_withdrawn, postal_code, frdocnum,
attachments_self_link, attachments_related_link, file_formats, display_properties
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
"""
cursor.execute(insert_query, values)
print(f"Document {document_id} inserted successfully.")
except Exception as e:
print(f"An error occurred: {e}")


# Main function to read JSON from file and insert into the database
# Main function to read JSON from file and insert into the database
def main():
if len(sys.argv) != 2:
Expand Down Expand Up @@ -129,6 +140,5 @@ def main():
except Exception as e:
print(f"An error occurred: {e}")


if __name__ == "__main__":
main()