Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import requests
- file = "requestlog-customer-charges.json"
- json_file = open(file)
- file_contents = json_file.read()
- dic = json.loads(file_contents)
- #print (dic[0]['request'])
- old_id_mappings = dict()
- for item in dic:
- req = item['request']
- req_url = "https://api.stripe.com" + req['url']
- parameters = req['body']
- header_info = req['headers']
- print (parameters)
- for id in old_id_mappings:
- #print ("Key-value pairs: ", id, old_id_mappings[id])
- parameters = parameters.replace(id, old_id_mappings[id])
- print ("After change: ", parameters)
- if req['method'] == "POST":
- response = requests.post(req_url, params=parameters, headers=header_info)
- else:
- response = requests.get(req_url, params=parameters, headers=header_info)
- #print (response)
- new_status_code = response.status_code
- new_body = response.json()
- #print (new_body)
- if 'id' in new_body:
- new_id = new_body['id']
- #print ("New ID: ", new_id)
- #print (response)
- old_response = item['response']
- old_status_code = old_response['code']
- parsed_body = json.loads(old_response['body'])
- #print(parsed_body)
- if 'id' in parsed_body:
- old_id = parsed_body['id']
- #print (old_id)
- old_id_mappings[old_id] = new_id
- #print (old_id_mappings)
- #print (new_status_code, old_status_code)
- if (new_status_code == old_status_code):
- print ("Success")
- else:
- print ("Status code do not Match.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement