Skip to content

Commit fcdf0a7

Browse files
committed
fix: schema_name updated
1 parent 0a6d955 commit fcdf0a7

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

main.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import glob
22
import io
3-
import json
43
import os
54
import shutil
65
import time
@@ -72,7 +71,7 @@ def polytabular(cursor, path, concept_name):
7271
def 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("../../")

services/trud_s3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ def get_trud_s3_object(key: str):
2121
logger.error(pce)
2222
except Exception as e:
2323
logger.exception(f"An error occurred: {e}")
24+
return None

0 commit comments

Comments
 (0)