From 6a0e87e665f8ea351cae8f72fa596a8b00b5c2dd Mon Sep 17 00:00:00 2001 From: javex Date: Tue, 26 Sep 2023 18:03:11 +0930 Subject: [PATCH] Add --quick flag to speed up runs while testing --- woolies.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/woolies.py b/woolies.py index 7292db9..ae99941 100644 --- a/woolies.py +++ b/woolies.py @@ -1,11 +1,12 @@ import requests import json +import sys class WooliesAPI: - def __init__(self): - + def __init__(self, quick=False): + self.quick = quick self.session = requests.Session() @@ -71,7 +72,8 @@ def get_category(self, cat_id): break # Temporary speedup - break + if self.quick: + break # Not done, go to next page request_data['pageNumber'] += 1 @@ -96,7 +98,10 @@ def save_cache(cache_data): def main(): - woolies = WooliesAPI() + quick = False + if len(sys.argv) > 1 and sys.argv[1] == "--quick": + quick = True + woolies = WooliesAPI(quick=quick) categories = woolies.get_categories() #categories = load_cache() for category_obj in categories: @@ -117,6 +122,9 @@ def main(): category = woolies.get_category(cat_id) all_category_bundles = list(category) category_obj['Products'] = all_category_bundles + + if quick: + break #save_cache(categories) with open('woolies_all.json', 'w') as f: f.write(json.dumps(categories))