11import glob
22import io
3- import json
43import os
54import shutil
65import time
@@ -72,7 +71,7 @@ def polytabular(cursor, path, concept_name):
7271def run (trud_s3_key : str ):
7372 start_time = time .time ()
7473
75- schema_name = trud_s3_key .split ("/" ).pop ()[ 7 : - 6 ]. replace ("." , "_" )
74+ schema_name = str . format ( trud_s3_key .split ("/" ).pop (). split (".zip" ). pop ( 0 ) )
7675
7776 logger .info (f"Processing => { schema_name } " )
7877 if not schema_name :
@@ -81,8 +80,8 @@ def run(trud_s3_key: str):
8180 else :
8281 trud_s3_zip_content = get_trud_s3_object (trud_s3_key )
8382 if not trud_s3_zip_content :
84- logger .info (f"Skipping as no data found in storage => { schema_name } . " )
85- return f"No trud data found for schema { schema_name } . " , 400
83+ logger .info (f"Skipping as no data found in storage => { schema_name } " )
84+ return f"No trud data found for schema { schema_name } " , 400
8685 else :
8786 logger .info (f"Extracting zip content => { schema_name } " )
8887 zip_extract_dir = f"./extracts/{ schema_name } "
@@ -94,8 +93,8 @@ def run(trud_s3_key: str):
9493 cursor = cnx .cursor ()
9594
9695 logger .info (f"Creating schema => { schema_name } " )
97- cursor .execute ('CREATE SCHEMA IF NOT EXISTS "{}";' . format ( schema_name ) )
98- cursor .execute ('SET search_path TO "{}";' . format ( schema_name ) )
96+ cursor .execute (f 'CREATE SCHEMA IF NOT EXISTS "{ schema_name } ";' )
97+ cursor .execute (f 'SET search_path TO "{ schema_name } ";' )
9998
10099 logger .info ("Importing table structure..." )
101100 with open (dmd_structure_path , "r" ) as f :
@@ -112,8 +111,7 @@ def run(trud_s3_key: str):
112111 "Appending nhs queue list into 'medicine.nhs_medicine_api_data_process' table..."
113112 )
114113 insert_command = "INSERT INTO medicine.nhs_medicine_api_data_process (schema_name, status) VALUES (%s, %s);"
115- data = (format (schema_name ), 1 )
116- cursor .execute (insert_command , data )
114+ cursor .execute (insert_command , (schema_name , 1 ))
117115
118116 cnx .commit ()
119117 os .chdir ("../../" )
0 commit comments