codextj

json_req_script

Oct 1st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import requests
  2. import time
  3. import json
  4.  
  5.  
  6. def get_id2(pid):
  7.     url2 = ('http://www.supremenewyork.com/shop/' + pid + '.json')
  8.     data2 = requests.get(url2).json()
  9.     print('style',url2)
  10.     for sid in data2['styles']:
  11.             print('name',sid['name'],'id',sid['id'])
  12.  
  13.  
  14.  
  15. def get_id():
  16.     url = 'http://www.supremenewyork.com/shop.json'
  17.     data = requests.get(url).json()
  18.     filename = 'ids.txt'
  19.     with open(filename, 'a+') as rw_af:
  20.         file_url_lst = rw_af.read()
  21.         for category in data['products_and_categories'].values():
  22.             for product_id in category:
  23.                item_id = str(product_id['id'])
  24.                if item_id not in file_url_lst:
  25.                    rw_af.write(item_id+'\n')
  26.                    get_id2(item_id)
  27.  
  28.  
  29. if __name__ == "__main__":
  30.     get_id()
Add Comment
Please, Sign In to add comment