codextj

supreme_montor_dev_version

Oct 4th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import requests
  2. import time
  3. import json
  4.  
  5. # Author: codextj
  6. in_stock = []   # stock_level 1
  7. out_stock = []  # stock_level 0
  8.  
  9. def get_id2(pid):
  10.     url2 = ('http://www.supremenewyork.com/shop/' + pid + '.json')
  11.     data2 = requests.get(url2).json()
  12.     print('.',end='')
  13.     # print('style',url2)
  14.     for style_idx in data2['styles']:
  15.         style_name = style_idx['name'] # color
  16.         style_id = style_idx['id']
  17.        
  18.         for size_idx in style_idx['sizes']:
  19.             stock_info_dict = {
  20.                  'style_id' : style_id,
  21.                  'size_name' : size_idx["name"],
  22.                  'size_id':size_idx['id']
  23.                  }
  24.            
  25.             if size_idx["stock_level"] == 1 :
  26.                 in_stock.append(stock_info_dict)
  27.             else:
  28.                 out_stock.append(stock_info_dict)
  29.  
  30.  
  31.  
  32. def get_id():
  33.     url = 'http://www.supremenewyork.com/shop.json'
  34.     data = requests.get(url).json()
  35.     filename = 'ids.txt'
  36.     with open(filename, 'a+') as rw_af:
  37.         file_url_lst = rw_af.read()
  38.         for category in data['products_and_categories'].values():
  39.             for product_id in category:
  40.                item_id = str(product_id['id'])
  41.                if item_id not in file_url_lst:
  42.                    rw_af.write(item_id+'\n')
  43.                    get_id2(item_id)
  44.  
  45.  
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     get_id()
  50.     print('\nstock_status')
  51.     print('in stock')
  52.     for stk_info in in_stock:
  53.         print(stk_info)
  54.     print('out of stock')
  55.     for stk_info in out_stock:
  56.         print(stk_info)
Add Comment
Please, Sign In to add comment