Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- import json
- # Author: codextj
- in_stock = [] # stock_level 1
- out_stock = [] # stock_level 0
- def get_id2(pid):
- url2 = ('http://www.supremenewyork.com/shop/' + pid + '.json')
- data2 = requests.get(url2).json()
- print('.',end='')
- # print('style',url2)
- for style_idx in data2['styles']:
- style_name = style_idx['name'] # color
- style_id = style_idx['id']
- for size_idx in style_idx['sizes']:
- stock_info_dict = {
- 'style_id' : style_id,
- 'size_name' : size_idx["name"],
- 'size_id':size_idx['id']
- }
- if size_idx["stock_level"] == 1 :
- in_stock.append(stock_info_dict)
- else:
- out_stock.append(stock_info_dict)
- def get_id():
- url = 'http://www.supremenewyork.com/shop.json'
- data = requests.get(url).json()
- filename = 'ids.txt'
- with open(filename, 'a+') as rw_af:
- file_url_lst = rw_af.read()
- for category in data['products_and_categories'].values():
- for product_id in category:
- item_id = str(product_id['id'])
- if item_id not in file_url_lst:
- rw_af.write(item_id+'\n')
- get_id2(item_id)
- if __name__ == "__main__":
- get_id()
- print('\nstock_status')
- print('in stock')
- for stk_info in in_stock:
- print(stk_info)
- print('out of stock')
- for stk_info in out_stock:
- print(stk_info)
Add Comment
Please, Sign In to add comment