I have code as follows:
try:
relations = open(file_name, "wb")
ftp.retrbinary('RETR {0}'.format(file_name), test)
relations.close() # Closes the local file
ftp.quit() # Closes the ftp connection
print("FTP Connection quited.")
except Exception as e:
print("Error: File {0} could not be downloaded. {1}".format(file_name, str(e)))
And the test function is as follows:
def test(data):
data_n = json.dumps(data.decode('utf-8'))
pdb.set_trace()
pass
I want to download the file from ftp server using python and read it without writing it locally.
In this case in test function in data_n i get:
'"CODE;MATCHCODE;\\r\\nK902154;VANHOVEGARAGES;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\\r\\nK902191;CARAVENUESTAR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\\r\\nK902192;CARAVENUESTAR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"'
How can I convert it to the list of dictionaries as follows:
result = [
{
"CODE": "K902154",
"MATCHCODE": "VANHOVEGARAGES"
},
{
"CODE": "K902191",
"MATCHCODE": "CARAVENUESTAR"
},
{
"CODE": "K902192",
"MATCHCODE": "CARAVENUESTAR"
}
]