i am making something to monitor a site for new products, so im trying to add all the titles to a json file, that starts out with {"product_titles": []}
,
im trying to figure our how to add the dicts that contain the product title and sizes to the empty list
this is my code
import requests
import json
url = 'https://www.supremenewyork.com/mobile_stock.json'
headers = {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
'Accept': 'application/json',
'Accept-Encoding': 'br, gzip, deflate',
'Accept-Language': 'en-us'
}
req = requests.get(url, headers=headers)#
page = req.json()
categories = page['products_and_categories']
Sweatshirts = categories['Sweatshirts']
product_list = []
for sweater in Sweatshirts:
product_name = sweater['name']
product_colors = []
product_sizes = []
product_stock_levels = []
#print(product_name)
raw_product_info = requests.get('https://www.supremenewyork.com/shop/' + str(sweater['id']) + '.json', headers=headers)
product_info = raw_product_info.json()
styles = product_info['styles']
for style in styles:
colors = style['name']
full_product_name = product_name + colors
file = open
product_colors.append(colors)
for size in style['sizes']:
sizes = {size['name'] : size['stock_level']}
product_sizes.append(sizes)
with open('supreme.json', 'r+') as supremef:
data = json.load(supremef)
dump = json.dump(data['product_titles'].append({full_product_name: sizes}), supremef)
the last few lines in where i try to add it to the list in the json file but its not adding it to it