<jupyter_start><jupyter_text>Tip: To query for updates or deltas since you last walked through the result set you can use the itemUpdateDate attribute. To ensure that your query results include changes to a product’s active/inactive status, add active=* to your query parameters. For example: .../v1/products(itemUpdateDate>2017-02-06T16:00:00&active=*)?format=json&pageSize=100&cursorMark=*&apiKey=YOUR_API_KEYFor example: .../v1/products(itemUpdateDate>today&active=*)?format=json&pageSize=100&cursorMark=*&apiKey=YOUR_API_KEY"https://api.bestbuy.com/v1/products(releaseDate>today)?format=json&show=sku,name,salePrice&apiKey=YourAPIKey"<jupyter_code>bb_root = config_bestbuy.path
bb_dir = 'best_buy_20211123'
bb_path = os.path.join(bb_root, bb_dir)

bb_filename = 'best_buy_20211123_00001 - Copy.json'
bb_file_path = os.path.join(f'{bb_path}\\products', bb_filename)

with open(bb_file_path, 'r') as f:
    io = json.load(f)

nextcursorMark = "*"
api_index = 3
page_size = 100
days = 2

r = api_bestbuy(cursorMark=nextcursorMark, api_index=api_index, page_size=page_size, days=days)
# io = r.json()

cols = ['nextCursorMark', 'total', 'totalPages', 'queryTime', 'totalTime', 'canonicalUrl', 'sku', 'name', 'type', 'startDate', 'new', 'activeUpdateDate', 'active', 'regularPrice', 'salePrice', 'clearance', 'onSale', 'categoryPath', 'customerReviewCount', 'customerReviewAverage', 'priceUpdateDate', 'itemUpdateDate', 'class', 'classId', 'subclass', 'subclassId', 'department', 'departmentId', 'images', 'image', 'color']
io = r.json()
df_meta = pd.DataFrame(io)
df_meta = df_meta.iloc[:, :-1]
df_products = pd.DataFrame(io['products'])
df = df_meta.merge(df_products, how='inner', left_index=True, right_index=True)
df = df.loc[:, cols]
df.insert(0, 'request_timestamp', datetime.utcnow())
api_index=3
folderpath, datename, engine, db_cols, last_update_date = initialize(folder_index=api_index)
last_update_date

db = os.path.join(config_bestbuy.path, 'bestbuy.db')
conn_string = f'sqlite:///{db}'
engine = create_engine(conn_string)

with engine.connect() as cnx:
    # df.to_sql(name='products', con=cnx, if_exists='replace', index=False)
    df_test = pd.read_sql(sql='select max(itemUpdateDate) from products', con=cnx)
    rs = cnx.execute("select max(itemUpdateDate) from products")
    for row in rs:
        print(row)

df_test.iloc[0, 0]
today = datetime.utcnow().date()
n_days = datetime.utcnow().date() - timedelta(days=2)
n_hours = (today-n_days)/timedelta(seconds=1)
n_hours
['nextCursorMark', 'total', 'totalPages', 'queryTime', 'totalTime', 'canonicalUrl', 'sku', 'name', 'type', 'startDate', 'new', 'activeUpdateDate', 'active', 'regularPrice', 'salePrice', 'clearance', 'onSale', 'categoryPath', 'customerReviewCount', 'customerReviewAverage', 'priceUpdateDate', 'itemUpdateDate', 'class', 'classId', 'subclass', 'subclassId', 'department', 'departmentId', 'images', 'image', 'color']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1660415956358677, 'fraction_numerical': 0.01909307875894988, 'mean_word_length': 7.654867256637168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '28986', 'license': 'MIT', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1029, 'n_words': 210, 'path': 'api_bestbuy v3.ipynb', 'repo_name': 'andrewcchoi/api_bestbuy', 'size': '2933'}