Skip to content

Commit d1f5b07

Browse files
committed
Merge branch 'main' into update_wait_for_entire_page_load
2 parents 690b0b6 + bb38c2a commit d1f5b07

File tree

19 files changed

+333
-63
lines changed

19 files changed

+333
-63
lines changed

.github/workflows/precommit.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Pre-commit checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
pre-commit:
9+
name: Pre-commit checks
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
14+
15+
- name: Install Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.11"
19+
20+
#----------------------------------------------
21+
# ----- install & configure poetry -----
22+
#----------------------------------------------
23+
- name: Install Poetry
24+
uses: snok/install-poetry@v1
25+
with:
26+
version: 1.8.3
27+
virtualenvs-create: false
28+
virtualenvs-in-project: true
29+
installer-parallel: true
30+
31+
#----------------------------------------------
32+
# ----- install dependencies -----
33+
#----------------------------------------------
34+
- name: Install dependencies
35+
run: |
36+
poetry install --no-interaction --no-root --with dev
37+
38+
- name: Lint check
39+
run: pylint --disable=R,C application_examples examples
40+
41+
- name: Code style check
42+
run: black . --check
43+
44+
- name: Imports sort check
45+
uses: isort/isort-action@master
46+
47+
- name: Static check
48+
uses: jakebailey/pyright-action@v2
49+
continue-on-error: true
50+
with:
51+
pylance-version: latest-release

application_examples/flight_price_tracker/flight_price_tracker.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""""This is an example of how to use AgentQL to track the cheapest flight price from Skyscanner website."""
2+
23
import agentql
34
from agentql.sync_api import ScrollDirection
45

@@ -21,8 +22,8 @@
2122
webgl_vendor=VENDOR_INFO,
2223
webgl_renderer=RENDERER_INFO,
2324
nav_user_agent=USER_AGENT_INFO,
24-
)
25-
25+
)
26+
2627
# Define the queries to interact with the page (You could tweak the queries as per item you want to track on the website)
2728
QUERY_1 = """
2829
{
@@ -72,7 +73,7 @@
7273
depart_date_picker
7374
}
7475
"""
75-
76+
7677
response_5 = session.query(QUERY_5)
7778

7879
response_5.depart_date_picker.click(force=True)
@@ -127,6 +128,3 @@
127128

128129
# Stop the session
129130
session.stop()
130-
131-
132-

application_examples/sentiment_analysis_youtube_comments.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from openai import OpenAI
21
import agentql
2+
from openai import OpenAI
33

44
URL = "https://www.youtube.com/watch?v=JfM1mr2bCuk"
55

@@ -17,7 +17,7 @@
1717

1818
# Wait for the page to load (helps to load the comments on the video)
1919
driver.wait_for_page_ready_state()
20-
20+
2121
# Define the queries to interact with the page
2222
QUERY = """
2323
{
@@ -47,23 +47,20 @@
4747
for comment in response_data["comments"]:
4848
USER_MESSAGE += comment["comment_text"]
4949

50-
5150
SYSTEM_MESSAGE = """You are an expert in understanding the social media analytics and analysis and specialize in analyzing sentiment of the comments.
5251
Please find the comments on the video as follows:
5352
5453
"""
55-
54+
5655
USER_MESSAGE += "Could you please provide a summary of the comments on the video. Additionaly, just give only 3 takeaways which would be important for me as the creator of the video."
5756

5857
completion = client.chat.completions.create(
5958
model="gpt-3.5-turbo",
6059
messages=[
61-
{ "role": "system", "content": SYSTEM_MESSAGE },
62-
{ "role": "user", "content": USER_MESSAGE },
63-
]
60+
{"role": "system", "content": SYSTEM_MESSAGE},
61+
{"role": "user", "content": USER_MESSAGE},
62+
],
6463
)
6564

6665
# Print the response from the GPT-3.5 model (Sentiment Analysis of the comments on the video)
6766
print(completion.choices[0].message.content)
68-
69-

application_examples/xpath/xpath.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import agentql
22

3-
#import https://pypi.org/project/playwright-dompath/
3+
# import https://pypi.org/project/playwright-dompath/
44
# Playwright Dompath is a Python library that helps you to generate XPath from Playwright selectors.
55
from playwright_dompath.dompath_sync import xpath_path
66

@@ -18,11 +18,10 @@
1818

1919
print(response.about_link.text_content())
2020

21-
# Get the XPath
21+
# Get the XPath
2222
print("XPath:", xpath_path(response.search_btn))
2323

2424
response.search_box.fill("tinyfish")
2525
response.search_btn.click(force=True)
2626

2727
session.stop()
28-

examples/async_example/async_example.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
"""This example demonstrates how to levergae to_data() method provided by AgentQL."""
2-
import agentql
2+
33
import asyncio
44

5+
import agentql
6+
57
# Set the URL to the desired website
6-
WALMART_URL = "https://www.walmart.com/ip/Nintendo-Switch-OLED-Model-w-White-Joy-Con/910582148?athbdg=L1600"
8+
WALMART_URL = (
9+
"https://www.walmart.com/ip/Nintendo-Switch-OLED-Model-w-White-Joy-Con/910582148?athbdg=L1600"
10+
)
711
TARGET_URL = "https://www.target.com/p/nintendo-switch-oled-model-with-white-joy-con/-/A-83887639#lnk=sametab"
812
NINETENDO_URL = "https://www.nintendo.com/us/store/products/nintendo-switch-oled-model-white-set/"
913

14+
1015
def print_header():
1116
"""Prints the header for the data table"""
1217
print(f"{'Website':<25} | {'Product ':<20} | {'Price ':<20} ")
1318
print("-" * 75)
1419

20+
1521
def print_row(website, product, price):
1622
"""Prints the data row"""
1723
print(f"{website:<25} | {product:<20} | {price:<20} ")
1824

25+
1926
async def fetch_price(session_url, query):
2027
session = await agentql.start_async_session(session_url)
2128
await session.driver.wait_for_page_ready_state()
@@ -24,8 +31,8 @@ async def fetch_price(session_url, query):
2431
await session.stop()
2532
return data["price"]
2633

34+
2735
async def get_price_across_websites():
28-
2936

3037
# Define the queries to interact with the page
3138
PRODUCT_INFO_QUERY = """
@@ -42,12 +49,13 @@ async def get_price_across_websites():
4249
walmart_price, nintendo_price, target_price = await asyncio.gather(
4350
fetch_price(WALMART_URL, PRODUCT_INFO_QUERY),
4451
fetch_price(NINETENDO_URL, PRODUCT_INFO_QUERY),
45-
fetch_price(TARGET_URL, PRODUCT_INFO_QUERY)
52+
fetch_price(TARGET_URL, PRODUCT_INFO_QUERY),
4653
)
4754

4855
print_row("Walmart", "Nintendo Switch", walmart_price)
4956
print_row("Nintendo site", "Nintendo Switch", nintendo_price)
5057
print_row("Target", "Nintendo Switch", target_price)
5158

59+
5260
if __name__ == "__main__":
53-
asyncio.run(get_price_across_websites())
61+
asyncio.run(get_price_across_websites())
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example script: customize a web drive with AgentQL
2+
3+
This example demonstrates how to customize the web driver used by AgentQL.
4+
5+
## Run the script
6+
7+
* [Install AgentQL SDK](https://docs.agentql.com/docs/installation/sdk-installation)
8+
* Save this python file locally as **customizing_web_driver.py**
9+
* Run the following command from the project's folder:
10+
```bash
11+
python3 customizing_web_driver.py
12+
```
13+
14+
## Play with it
15+
16+
Install the [AgentQL Chrome DevTools extension](https://docs.agentql.com/docs/installation/chrome-extension-installation/) to play with the AgentQL query. [Learn more about the AgentQL query language](https://docs.agentql.com/docs/agentql-query/query-intro)

examples/customizing_web_driver/customizing_web_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This example demonstrates how to customize the web driver used by AgentQL."""
2+
23
import agentql
34

45
# Importing the default PlaywrightWebDriver from AgentQL library

examples/debug_script/debug_agentql_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
logging.basicConfig(level=logging.DEBUG)
99
log = logging.getLogger(__name__)
1010

11+
1112
def debug_manager_showcase():
1213
# The following context manager will enable debug mode for the script.
1314
with DebugManager.debug_mode():

examples/debug_support_methods/last_query.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
""" This example demonstrates how to use the last_query and last_response attributes of the session object to debug the queries and responses. """
2+
23
import agentql
34

45
# Set the URL to the desired website
5-
URL ="https://www.badmintonwarehouse.com/"
6+
URL = "https://www.badmintonwarehouse.com/"
67

78
if __name__ == "__main__":
89
# Start a session with the specified URL
@@ -18,10 +19,10 @@
1819

1920
# Fetch the response of the query
2021
response = session.query(HOMEPAGE_QUERY)
21-
22+
2223
response.search_box.fill("Mavis 350 Nylon Shuttlecock (Yellow/Fast)")
2324
response.search_btn.click(force=True)
24-
25+
2526
CHOOSE_PRODUCT_QUERY = """
2627
{
2728
products[]
@@ -71,7 +72,7 @@
7172
response = session.query(ADD_TO_CART_QUERY)
7273

7374
response.add_to_cart_btn.click(force=True)
74-
75+
7576
else:
7677
print("Let's wait for sale, current price is too high: ", response.product.to_data())
7778

@@ -80,6 +81,3 @@
8081
print("This was the last query executed ", session.last_query)
8182

8283
print("This was the last response received ", session.last_response)
83-
84-
85-

examples/default_driver/default_driver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This example demonstrates how to work with web driver configuration (headless) used by AgentQL."""
2+
23
import agentql
34

45
# Set the URL to the desired website
@@ -11,7 +12,7 @@
1112
search_input
1213
search_btn
1314
}"""
14-
15+
1516
# Start a session with the specified URL and the custom driver
1617
session = agentql.start_session(URL)
1718

@@ -35,5 +36,3 @@
3536

3637
# Stop the session
3738
session.stop()
38-
39-

examples/default_popup_handler/default_popup_handler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""This example demonstrates how to use the default popup handler to close all popups."""
2+
23
import time
3-
import agentql
44

5+
import agentql
56
from agentql.sync_api import close_all_popups_handler
67

78
# Set the URL to the desired website
89
URL = "https://kinfield.com/"
910

1011
if __name__ == "__main__":
11-
12+
1213
session = agentql.start_session(URL)
1314

1415
# Define the queries to interact with the page
@@ -27,4 +28,4 @@
2728
time.sleep(5)
2829

2930
# Stop the session
30-
session.stop()
31+
session.stop()

examples/ecommerce_pricing_data/pricing_data.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"""
55

66
import asyncio
7-
from playwright.async_api import async_playwright
7+
88
from agentql.ext.playwright.async_api import Page
9+
from playwright.async_api import async_playwright
910

1011
# URL of the ecommerce website
1112
# You can replace it with any other ecommerce website but the queries should be updated accordingly
@@ -106,9 +107,7 @@ async def extract_pricing_data(
106107
) -> list:
107108
"""Extract pricing data for a product within a price range."""
108109
# Search for the product with the specified price range
109-
print(
110-
f"Searching for product: {product} with price range: ${min_price} - ${max_price}"
111-
)
110+
print(f"Searching for product: {product} with price range: ${min_price} - ${max_price}")
112111
await _search_product(page, product, min_price, max_price)
113112

114113
current_page = 1

examples/leveraging_to_data_method/levaraging_to_data_method.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This example demonstrates how to leverage to_data() method provided by AgentQL."""
2+
23
import agentql
34

45
# Set the URL to the desired website
@@ -31,4 +32,4 @@
3132
print(data)
3233

3334
# Stop the session
34-
session.stop()
35+
session.stop()

0 commit comments

Comments
 (0)