I'm kinda noob at python (just learned a few codes watching Youtube videos)
What I'm trying to do:
- I have a file named deposits.json with multiple JSON, like bellow
[ {
"locator":"TRANSACAO448",
"storeCode":"loja01",
"deviceCode":"teste01",
"eventDate":"2020-04-01 09:30:53",
"memberIdentification":"04153883506",
"employeeIdentification":"",
"offerCode":"4",
"points":10,
"purchaseValue":1,
"additionalInformation":[
{
"key":"CODMOVPON",
"value":"1"
}
]
},
{
"locator":"TRANSACAO448",
"storeCode":"loja01",
"deviceCode":"teste01",
"eventDate":"2020-04-01 09:30:53",
"memberIdentification":"04153883506",
"employeeIdentification":"",
"offerCode":"4",
"points":10,
"purchaseValue":1,
"additionalInformation":[
{
"key":"CODMOVPON",
"value":"1"
}
]
}]
- Have the script bellow that send post to an intern API
with open('deposits.json', 'r') as infile:
# Variable for building our JSON block
json_block = []
for line in infile:
# Add the line to our JSON block
json_block.append(line)
# Check whether we closed our JSON block
if line.startswith('{'):
# Do something with the JSON dictionary
json_dict = json.loads(''.join(json_block))
a = json_dict
# Start a new block
#Request com os parametros para envio, como tipo e url de destino
r = requests.post(url, data=json.dumps(a) ,headers=headers,timeout=60)
print "------------------------------------------------------------------------------------"
print "Request:"
print json.dumps(a)
print "Data_envio:"+data_envio_completa
print (r)
print (r.text)
print "------------------------------------------------------------------------------------"
#salva o resultado em um txt com a data de envio no nome
with open (data_envio+'_log_transacoes.txt','wb') as l:
l.write(json.dumps(a))
l.write('Status: '+str(r.status_code))
l.write(r.text.encode('utf-8'))
json_block = []
Issue is: I need to send one request per time like a LOP because this API don't accept [{json},{json}] only {json} and the code like is right now only send 1 request, doesnt metter how many lines there is in JSON file.
Can somebody help me?