Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import json
  2. import requests
  3.  
  4. file = "requestlog-customer-charges.json"
  5. json_file = open(file)
  6. file_contents = json_file.read()
  7. dic = json.loads(file_contents)
  8. #print (dic[0]['request'])
  9. old_id_mappings = dict()
  10. for item in dic:
  11. req = item['request']
  12. req_url = "https://api.stripe.com" + req['url']
  13. parameters = req['body']
  14. header_info = req['headers']
  15. print (parameters)
  16. for id in old_id_mappings:
  17. #print ("Key-value pairs: ", id, old_id_mappings[id])
  18. parameters = parameters.replace(id, old_id_mappings[id])
  19.  
  20. print ("After change: ", parameters)
  21. if req['method'] == "POST":
  22. response = requests.post(req_url, params=parameters, headers=header_info)
  23. else:
  24. response = requests.get(req_url, params=parameters, headers=header_info)
  25. #print (response)
  26. new_status_code = response.status_code
  27. new_body = response.json()
  28. #print (new_body)
  29. if 'id' in new_body:
  30. new_id = new_body['id']
  31. #print ("New ID: ", new_id)
  32. #print (response)
  33. old_response = item['response']
  34. old_status_code = old_response['code']
  35.  
  36. parsed_body = json.loads(old_response['body'])
  37. #print(parsed_body)
  38. if 'id' in parsed_body:
  39. old_id = parsed_body['id']
  40. #print (old_id)
  41. old_id_mappings[old_id] = new_id
  42. #print (old_id_mappings)
  43. #print (new_status_code, old_status_code)
  44. if (new_status_code == old_status_code):
  45. print ("Success")
  46. else:
  47. print ("Status code do not Match.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement