From 5d54afe8fe49e5e42187fa261cb327436c6cf1c6 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Feb 2023 23:27:50 -0500 Subject: [PATCH] [F] Fix while loop logic --- mobile.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mobile.py b/mobile.py index 4af26c2..aa5c8c6 100644 --- a/mobile.py +++ b/mobile.py @@ -93,17 +93,19 @@ def crawl(item_url: str) -> dict: id = get_url_param(item_url, 'id') out_path = Path(f'crawler/{id}.json') + if out_path.is_file(): + return json.loads(out_path.read_text()) + while True: - if not out_path.is_file(): - print(f'Crawling {id}...') - out_path.parent.mkdir(parents=True, exist_ok=True) - resp = r.post('https://front.superbuy.com/crawler/', data={"needSoldOutSkuInfo": 1, "location": 2, "goodUrl": item_url}) - if resp.status_code != 200: - print(f"Request failed: {resp.status_code}") - assert input("Retry? [y/N]").lower() == 'y' - continue - out_path.write_text(resp.text) - return resp.json() + print(f'Crawling {id}...') + out_path.parent.mkdir(parents=True, exist_ok=True) + resp = r.post('https://front.superbuy.com/crawler/', data={"needSoldOutSkuInfo": 1, "location": 2, "goodUrl": item_url}) + if resp.status_code != 200: + print(f"Request failed: {resp.status_code}") + assert input("Retry? [y/N]").lower() == 'y' + continue + out_path.write_text(resp.text) + return resp.json() def create_diy_order(create: list[TaobaoOrder]):