diff --git a/examples/python/collect_paginated_ecommerce_listing_data/main.py b/examples/python/collect_paginated_ecommerce_listing_data/main.py index 34890f64..696379e3 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 f539fab1..53a4e1b7 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 b732abe4..739fec2d 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 8032e700..6120a62d 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 a5b7f7a0..3a6c1589 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 16957336..0ae078f3 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 0e04ea72..774c3947 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__":