From 4472c4986c53bbabbef89faf75fd7f549d39507e Mon Sep 17 00:00:00 2001 From: mueed Date: Wed, 30 Sep 2026 23:55:29 +0500 Subject: [PATCH] style: fix black, isort and pylint failures in examples/python examples/python is not covered by CI. .github/workflows/python-precommit.yml filters on examples/Python/** (capital P) but the directory is examples/python, and GitHub Actions path filters are case-sensitive, so the workflow has never run. The lint step also targeted application_examples examples, neither of which exists here. A follow-up PR fixes the workflow paths. This PR clears the pre-existing debt it will surface so that PR can turn CI on green. Split deliberately: the debt here is unrelated to the path bug, and this change is mechanical and independently reviewable. 7 files touched: - news-aggregator/main.py: E1205 x2 resolved to f-strings (logging-format-style=new per .pylintrc:396), black reformatted trailing whitespace/indentation at lines 51-53 - news-aggregator/main_sync.py: E1205 x2 resolved to f-strings - collect_paginated_ecommerce_listing_data/main.py: W1514 + W1309 on open(); black slice spacing - collect_paginated_news_headlines/main.py: W1514 on open() - compare_product_prices/async_main.py: black formatting (tuple unpacking, print collapse) - humanlike-antibot/main.py: isort import grouping - maps_scraper/main.py: isort import grouping Note: news-aggregator/main.py:45-47 and compare_product_prices/async_main.py:47-49 contain the same broken async with await browser.new_context() pattern as .templates/python/template_async.py:21-23. This PR reformats those lines without fixing the bug; that is left as a separate contribution. --- .../main.py | 7 +++---- .../collect_paginated_news_headlines/main.py | 5 ++--- .../python/compare_product_prices/async_main.py | 8 +++----- examples/python/humanlike-antibot/main.py | 3 +-- examples/python/maps_scraper/main.py | 3 +-- examples/python/news-aggregator/main.py | 15 ++++++--------- examples/python/news-aggregator/main_sync.py | 7 +++---- 7 files changed, 19 insertions(+), 29 deletions(-) diff --git a/examples/python/collect_paginated_ecommerce_listing_data/main.py b/examples/python/collect_paginated_ecommerce_listing_data/main.py index 34890f643..696379e37 100644 --- a/examples/python/collect_paginated_ecommerce_listing_data/main.py +++ b/examples/python/collect_paginated_ecommerce_listing_data/main.py @@ -1,9 +1,8 @@ import json import logging -from playwright.sync_api import sync_playwright - import agentql +from playwright.sync_api import sync_playwright logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) @@ -33,7 +32,7 @@ # limit the total number of books to 50 if len(response["books"]) + len(books) > 50: - books.extend(response["books"][:50 - len(books)]) + books.extend(response["books"][: 50 - len(books)]) else: books.extend(response["books"]) @@ -44,5 +43,5 @@ if pagination_info.has_next_page: pagination_info.navigate_to_next_page() - with open(f"./books.json", "w") as f: + with open("./books.json", "w", encoding="utf-8") as f: json.dump(books, f, indent=4) diff --git a/examples/python/collect_paginated_news_headlines/main.py b/examples/python/collect_paginated_news_headlines/main.py index f539fab1f..53a4e1b72 100644 --- a/examples/python/collect_paginated_news_headlines/main.py +++ b/examples/python/collect_paginated_news_headlines/main.py @@ -1,12 +1,11 @@ import json import logging -from playwright.sync_api import sync_playwright - import agentql # import paginate tool from agentql tools from agentql.tools.sync_api import paginate +from playwright.sync_api import sync_playwright logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) @@ -29,6 +28,6 @@ paginated_data = paginate(page, QUERY, 3) # save the aggregateddata to a json file - with open("./hackernews_paginated_data.json", "w") as f: + with open("./hackernews_paginated_data.json", "w", encoding="utf-8") as f: json.dump(paginated_data, f, indent=4) log.debug("Paginated data has been saved to hackernews_paginated_data.json") diff --git a/examples/python/compare_product_prices/async_main.py b/examples/python/compare_product_prices/async_main.py index b732abe49..739fec2d5 100644 --- a/examples/python/compare_product_prices/async_main.py +++ b/examples/python/compare_product_prices/async_main.py @@ -48,19 +48,17 @@ async def get_price_across_websites(): headless=False ) as browser, await browser.new_context() as context: # Open multiple tabs in the same browser context to fetch prices concurrently - (bestbuy_price, ebay_price, telquest_price) = await asyncio.gather( + bestbuy_price, ebay_price, telquest_price = await asyncio.gather( fetch_price(context, BESTBUY_URL), fetch_price(context, EBAY_URL), fetch_price(context, TELQUEST_URL), ) - print( - f""" + print(f""" Price at BestBuy: {bestbuy_price} Price at Target: {ebay_price} Price at Telquest: {telquest_price} - """ - ) + """) if __name__ == "__main__": diff --git a/examples/python/humanlike-antibot/main.py b/examples/python/humanlike-antibot/main.py index 8032e7000..6120a62d3 100644 --- a/examples/python/humanlike-antibot/main.py +++ b/examples/python/humanlike-antibot/main.py @@ -1,9 +1,8 @@ import random import time -from playwright.sync_api import ElementHandle, Page, sync_playwright - import agentql +from playwright.sync_api import ElementHandle, Page, sync_playwright def random_mouse_movement(page: Page): diff --git a/examples/python/maps_scraper/main.py b/examples/python/maps_scraper/main.py index a5b7f7a0f..3a6c15898 100644 --- a/examples/python/maps_scraper/main.py +++ b/examples/python/maps_scraper/main.py @@ -2,9 +2,8 @@ import os -from playwright.sync_api import sync_playwright - import agentql +from playwright.sync_api import sync_playwright # Set the URL to the Google Maps search for "boba tea" near Palo Alto URL = "https://www.google.com/maps/search/boba+tea/@37.4400289,-122.1653309,14z/data=!3m1!4b1?entry=ttu&g_ep=EgoyMDI1MDIxMS4wIKXMDSoASAFQAw%3D%3D" diff --git a/examples/python/news-aggregator/main.py b/examples/python/news-aggregator/main.py index 169573369..0ae078f36 100644 --- a/examples/python/news-aggregator/main.py +++ b/examples/python/news-aggregator/main.py @@ -4,9 +4,8 @@ import logging import os -from playwright.async_api import BrowserContext, async_playwright - import agentql +from playwright.async_api import BrowserContext, async_playwright # Set up logging logging.basicConfig(level=logging.INFO) @@ -46,12 +45,10 @@ async def main(): headless=True ) as browser, await browser.new_context() as context: # Open multiple tabs in the same browser context to fetch data concurrently - await asyncio.gather( - *(fetch_data(context, url) for url in WEBSITE_URLS) - ) - - # Update progress - log.info("All done! CSV is here: %s...", CSV_FILE_PATH) + await asyncio.gather(*(fetch_data(context, url) for url in WEBSITE_URLS)) + + # Update progress + log.info(f"All done! CSV is here: {CSV_FILE_PATH}...") async def fetch_data(context: BrowserContext, session_url): @@ -82,7 +79,7 @@ async def fetch_data(context: BrowserContext, session_url): file.writelines(new_lines) # Update progress - log.info("Fetched items from %s...", session_url) + log.info(f"Fetched items from {session_url}...") if __name__ == "__main__": diff --git a/examples/python/news-aggregator/main_sync.py b/examples/python/news-aggregator/main_sync.py index 0e04ea72b..774c3947e 100644 --- a/examples/python/news-aggregator/main_sync.py +++ b/examples/python/news-aggregator/main_sync.py @@ -3,9 +3,8 @@ import logging import os -from playwright.sync_api import BrowserContext, sync_playwright - import agentql +from playwright.sync_api import BrowserContext, sync_playwright # Set up logging logging.basicConfig(level=logging.INFO) @@ -43,7 +42,7 @@ def main(): # Process URLs sequentially in synchronous version for url in WEBSITE_URLS: fetch_data(context, url) - log.info("All done! CSV is here: %s", CSV_FILE_PATH) + log.info(f"All done! CSV is here: {CSV_FILE_PATH}") def fetch_data(context: BrowserContext, session_url): @@ -73,7 +72,7 @@ def fetch_data(context: BrowserContext, session_url): with open(CSV_FILE_PATH, "a", encoding="utf-8") as file: file.writelines(new_lines) - log.info("Fetched items from %s", session_url) + log.info(f"Fetched items from {session_url}") if __name__ == "__main__":