Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import json
  2. import requests
  3.  
  4. old_to_new = {}
  5. with open('requestlog-customer-charges.json') as requests_json:
  6. entries = json.load(requests_json)
  7.  
  8. for entry in entries:
  9. old_res = entry['response']
  10. old_code = old_res['code']
  11. old_body = json.loads(old_res['body'])
  12. old_id = old_body['id']
  13.  
  14. request = entry['request']
  15. url = 'https://api.stripe.com' + request['url']
  16. headers = request['headers']
  17. body: str = request['body']
  18.  
  19. for key_id in old_to_new:
  20. url = url.replace(key_id, old_to_new[key_id])
  21. body = body.replace(key_id, old_to_new[key_id])
  22.  
  23. method = request['method']
  24.  
  25. res = requests.request(method, url, headers=headers, data=body)
  26. assert res.status_code == old_code
  27.  
  28. new_body = res.json()
  29. new_id = new_body['id']
  30. old_to_new[old_id] = new_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement