Skip to content

Commit f083814

Browse files
committed
Consolidated some logic in the csv to json converter python file
1 parent 57e7be6 commit f083814

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

JavaScript/Node.js/processcsv.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def processcsvfile(fname,seperator,outdir,outfname):
7070

7171
for blob in blob_list:
7272
print("Processing blob : " + blob.name)
73-
blob_name = getfilename(blob.name).split('.')[0]
73+
blob_name = getfilename(blob.name)
74+
blob_name_without_extension = blob_name.split('.')[0]
7475
downloadedblob = "downloaded_" + blob_name
7576

7677
#Download the blob locally
@@ -79,13 +80,18 @@ def processcsvfile(fname,seperator,outdir,outfname):
7980
downloaded_blob_stream = blob_client.download_blob()
8081
my_blob.write(downloaded_blob_stream.readall())
8182

83+
output_dir = ""
84+
uploaded_blob_name = ""
85+
8286
if pattern is not None:
83-
json_outpath = processcsvfile(fname=downloadedblob,seperator="|",outfname=blob_name,outdir='jsonfiles/' + container + "/" + pattern)
84-
print("uploading blob " + json_outpath)
85-
with open(json_outpath, "rb") as data:
86-
container_client.upload_blob(name=str(pattern + 'json/' + blob_name + ".json"), data=data)
87+
output_dir = "jsonfiles/" + container + "/" + pattern
88+
uploaded_blob_name = str(pattern + 'json/' + blob_name_without_extension + ".json")
89+
8790
else:
88-
json_outpath = processcsvfile(fname=downloadedblob,seperator="|",outfname=blob_name,outdir='jsonfiles/' + container + "/")
89-
print("uploading blob " + json_outpath)
90-
with open(json_outpath, "rb") as data:
91-
container_client.upload_blob(name=str('json/' + blob_name + ".json"), data=data)
91+
output_dir = "jsonfiles/" + container + "/"
92+
uploaded_blob_name = str('json/' + blob_name_without_extension + ".json")
93+
94+
json_outpath = processcsvfile(fname=downloadedblob,seperator="|",outfname=blob_name_without_extension,outdir=output_dir)
95+
print("uploading blob " + json_outpath)
96+
with open(json_outpath, "rb") as data:
97+
container_client.upload_blob(name=uploaded_blob_name, data=data)

0 commit comments

Comments
 (0)