add exception handling/logging for json requests

This commit is contained in:
2024-12-08 01:23:15 +01:00
parent 029458c2b3
commit 3a1fb5cd33

View File

@@ -103,6 +103,7 @@ def cmd(conn: sqlite3.Connection):
timestamp = int(time.time())
logging.info('scraping at %d', timestamp)
try:
global_products = requests.request('GET', 'https://store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
us_products = requests.request('GET', 'https://us.store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
eu_products = requests.request('GET', 'https://eu.store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
@@ -110,6 +111,9 @@ def cmd(conn: sqlite3.Connection):
au_products = requests.request('GET', 'https://au.store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
ca_products = requests.request('GET', 'https://ca.store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
jp_products = requests.request('GET', 'https://jp.store.bambulab.com/collections/bambu-lab-3d-printer-filament/products.json').json()
except requests.exceptions.RequestException as e:
logging.error(f'request error: {e}')
return
all_products = {
'global': global_products['products'],