bccs_dump.py
def fetch_products_from_base_url(base_url):
    """Fetch all product definitions from the products.json endpoint
    """
    page_number = 1
    products = []
    prods = []
    more_pages = True

    while more_pages:
        req = requests.get(base_url + "/products.json?limit=250&page=" + str(page_number))
        if req.status_code == 200:
            new_products = req.json()['products']
            if len(new_products) == 0:
                more_pages = False
            else:
                products += req.json()['products']
                page_number += 1
                time.sleep(0.5)
        else:
            time.sleep(5)

    # Parse combined products.json into more usable data structure
    for p in products:
        if p['title'] == "Container Deposit Fee":
            continue
        try:
            thumb =  p['images'][0]['src']
        except IndexError:
            thumb = None

        sku_order_limits = {}
        for tag in p['tags']:
            if tag.startswith('brand::'):
                brand = tag.split('::')[-1]
            elif tag.startswith('b2b_order_limit'):
                for sku_limit in tag.split('::')[-1].split('|'):
                    sku, limit = sku_limit.split('=')
                    sku_order_limits[sku] = limit

        sizes = []
        for v in p['variants']:
            if v['available']:
                in_stock = "In Stock"
            else:
                in_stock = "Out of Stock"

            try:
                items_per_pack = int(v['title'].split(' ')[-1].split(')')[0])
                price_per_item = round(float(v['price']) / items_per_pack, 2)
            except:
                items_per_pack = None
                price_per_item = None

            lp_cut = '%0.2f' % round(float(v['price']) * 0.85, 2)
            bcldb_cut = '%0.2f' % round(float(v['price']) * 0.15, 2)

            updated = datetime.fromisoformat(v['updated_at']).strftime("%b %d %Y %H:%M:%S")
            sizes.append({'name': v['title'].replace('\n', ''),
                          'price': v['price'],
                          'in_stock':in_stock,
                          'price_per_item': price_per_item,
                          'order_limit': sku_order_limits.get(v['sku']),
                          'lp_cut': lp_cut,
                          'bcldb_cut': bcldb_cut,
                          'updated': updated,
                          'updated_sortable': v['updated_at']})

        prods.append({'name': p['title'],
                      'lp': p['vendor'],
                      'brand': brand,
                      'thumb': thumb,
                      'url': base_url + '/products/' + p['handle'],
                      'created': p['created_at'],
                      'sizes': sizes,
                      'id': p['handle']})

    return prods
Fetch all product definitions from the products.json endpoint
    
Fetch all product definitions from the products.json endpoint
Fetch all product definitions from the products . json endpoint
def fetch_products_from_base_url(base_url):
    page_number = 1
    products = []
    prods = []
    more_pages = True
    while more_pages:
        req = requests.get(base_url + "/products.json?limit=250&page=" + str(page_number))
        if req.status_code == 200:
            new_products = req.json()['products']
            if len(new_products) == 0:
                more_pages = False
            else:
                products += req.json()['products']
                page_number += 1
                time.sleep(0.5)
        else:
            time.sleep(5)
    for p in products:
        if p['title'] == "Container Deposit Fee":
            continue
        try:
            thumb =  p['images'][0]['src']
        except IndexError:
            thumb = None
        sku_order_limits = {}
        for tag in p['tags']:
            if tag.startswith('brand::'):
                brand = tag.split('::')[-1]
            elif tag.startswith('b2b_order_limit'):
                for sku_limit in tag.split('::')[-1].split('|'):
                    sku, limit = sku_limit.split('=')
                    sku_order_limits[sku] = limit
        sizes = []
        for v in p['variants']:
            if v['available']:
                in_stock = "In Stock"
            else:
                in_stock = "Out of Stock"
            try:
                items_per_pack = int(v['title'].split(' ')[-1].split(')')[0])
                price_per_item = round(float(v['price']) / items_per_pack, 2)
            except:
                items_per_pack = None
                price_per_item = None
            lp_cut = '%0.2f' % round(float(v['price']) * 0.85, 2)
            bcldb_cut = '%0.2f' % round(float(v['price']) * 0.15, 2)
            updated = datetime.fromisoformat(v['updated_at']).strftime("%b %d %Y %H:%M:%S")
            sizes.append({'name': v['title'].replace('\n', ''),
                          'price': v['price'],
                          'in_stock':in_stock,
                          'price_per_item': price_per_item,
                          'order_limit': sku_order_limits.get(v['sku']),
                          'lp_cut': lp_cut,
                          'bcldb_cut': bcldb_cut,
                          'updated': updated,
                          'updated_sortable': v['updated_at']})
        prods.append({'name': p['title'],
                      'lp': p['vendor'],
                      'brand': brand,
                      'thumb': thumb,
                      'url': base_url + '/products/' + p['handle'],
                      'created': p['created_at'],
                      'sizes': sizes,
                      'id': p['handle']})
    return prods
def fetch_products_from_base_url ( base_url ) : page_number = 1 products = [ ] prods = [ ] more_pages = True while more_pages : req = requests . get ( base_url + "/products.json?limit=250&page=" + str ( page_number ) ) if req . status_code == 200 : new_products = req . json ( ) [ 'products' ] if len ( new_products ) == 0 : more_pages = False else : products += req . json ( ) [ 'products' ] page_number += 1 time . sleep ( 0.5 ) else : time . sleep ( 5 ) for p in products : if p [ 'title' ] == "Container Deposit Fee" : continue try : thumb = p [ 'images' ] [ 0 ] [ 'src' ] except IndexError : thumb = None sku_order_limits = { } for tag in p [ 'tags' ] : if tag . startswith ( 'brand::' ) : brand = tag . split ( '::' ) [ - 1 ] elif tag . startswith ( 'b2b_order_limit' ) : for sku_limit in tag . split ( '::' ) [ - 1 ] . split ( '|' ) : sku , limit = sku_limit . split ( '=' ) sku_order_limits [ sku ] = limit sizes = [ ] for v in p [ 'variants' ] : if v [ 'available' ] : in_stock = "In Stock" else : in_stock = "Out of Stock" try : items_per_pack = int ( v [ 'title' ] . split ( ' ' ) [ - 1 ] . split ( ')' ) [ 0 ] ) price_per_item = round ( float ( v [ 'price' ] ) / items_per_pack , 2 ) except : items_per_pack = None price_per_item = None lp_cut = '%0.2f' % round ( float ( v [ 'price' ] ) * 0.85 , 2 ) bcldb_cut = '%0.2f' % round ( float ( v [ 'price' ] ) * 0.15 , 2 ) updated = datetime . fromisoformat ( v [ 'updated_at' ] ) . strftime ( "%b %d %Y %H:%M:%S" ) sizes . append ( { 'name' : v [ 'title' ] . replace ( '\n' , '' ) , 'price' : v [ 'price' ] , 'in_stock' : in_stock , 'price_per_item' : price_per_item , 'order_limit' : sku_order_limits . get ( v [ 'sku' ] ) , 'lp_cut' : lp_cut , 'bcldb_cut' : bcldb_cut , 'updated' : updated , 'updated_sortable' : v [ 'updated_at' ] } ) prods . append ( { 'name' : p [ 'title' ] , 'lp' : p [ 'vendor' ] , 'brand' : brand , 'thumb' : thumb , 'url' : base_url + '/products/' + p [ 'handle' ] , 'created' : p [ 'created_at' ] , 'sizes' : sizes , 'id' : p [ 'handle' ] } ) return prods
Fetch all product definitions from the products.json endpoint
Fetch all product definitions from the products . json endpoint
"""Fetch all product definitions from the products.json endpoint
    """ # Parse combined products.json into more usable data structure
base_url