-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TF-2147 Add template codes to fish-tank repo #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this! Let's tune a bit and we should be good to go!
template/async_template.py
Outdated
# Locate desired web elements using AgentQL's query_elements() method | ||
response = await page.query_elements(ELEMENTS_QUERY) | ||
# Update to use the actual query terms to interact with the elements | ||
await response.search_input.fill("search query") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await response.search_input.fill("search query") | |
await response.search_input.type("search query") |
template/sync_template.py
Outdated
|
||
# Update to use the actual query terms | ||
response.search_btn.click() | ||
response.search_input.fill("search query") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.search_input.fill("search query") | |
response.search_input.type("<Replace with needed search query>") |
template/sync_template.py
Outdated
def interact_with_elements(page: Page): | ||
"""Locate and interact with desired web elements.""" | ||
# Locate desired web elements using AgentQL's query_elements() method | ||
response = page.query_elements(ELEMENTS_QUERY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would inline queries inside methods, to keep query close to the data access (i.e. shape of data matches the query, and they should be near to refer to). Especiallly when you extract these pieces in nice methods
template/sync_template.py
Outdated
|
||
|
||
def main(): | ||
with sync_playwright() as playwright, playwright.chromium.launch(headless=True) as browser: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like we can be less verbose here, since it's local to the with-header, and the whole line is long
with sync_playwright() as playwright, playwright.chromium.launch(headless=True) as browser: | |
with sync_playwright() as p, p.chromium.launch(headless=True) as browser: |
response = page.query_elements(ELEMENTS_QUERY) | ||
|
||
# Update to use the actual query terms | ||
response.search_btn.click() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually one types first then clicks, lets change?
template/sync_template.py
Outdated
log = logging.getLogger(__name__) | ||
|
||
# Set the URL to the desired website | ||
URL = "WEBSITE_URL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can highlight placeholders
URL = "WEBSITE_URL" | |
URL = "<Replace with the correct url>" |
data = await page.query_data(DATA_QUERY) | ||
# Update to use the actual keys corresponding to query terms | ||
log.info(f"Prices fetched from {session_url}:") | ||
for product in data["products"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use " or ', but choose one and use them consistently
for product in data["products"]: | |
for product in data['products']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason ' is used in the following f-string is that simply using " will throw an error:
log.info(f"Product: {product['name']}, Price: {product['price']}")
Either single quote is used or we need to use \"
in f-string. And I think using double quotes outside of f-string conforms to the standard.
template/async_template.py
Outdated
log = logging.getLogger(__name__) | ||
|
||
# Set URLs to the desired websites | ||
WEBSITE_URL_1 = "URL_1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments about placeholders and inline queries as below for sync example
async def main(): | ||
"""Fetch data concurrently in the same browser session from multiple websites.""" | ||
async with async_playwright() as playwright, await playwright.chromium.launch( | ||
headless=False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is headless, the next one is headed. Let change to be consistent
template/sync_template.py
Outdated
fetch_data(page) | ||
|
||
|
||
def interact_with_elements(page: Page): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we don't need 2 methods, same as with async example above?
Resurfacing this to be reviewed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would all this work in cases when user doesn't have git configured on their machine?
Yes! I think so, we will not use any Git action for |
This PR fixes TF-2147 by adding template codes for both sync and async to fish-tank. These codes will be downloaded as skeleton code when users run
agentql new-script
command to set up a boilerplate for AgentQL script.