Clean up docker-compose and run Black formatter over entire codebase

This commit is contained in:
Keannu Christian Bernasol 2024-10-30 22:09:58 +08:00
parent 6c232b3e89
commit 069aba80b1
60 changed files with 1946 additions and 1485 deletions

View file

@ -1,11 +1,19 @@
from celery import shared_task
from webdriver.utils import setup_webdriver, selenium_action_template, google_search, get_element, get_elements
from webdriver.utils import (
setup_webdriver,
selenium_action_template,
google_search,
get_element,
get_elements,
)
from selenium.webdriver.common.by import By
from search_results.tasks import create_search_result
# Task template
@shared_task(autoretry_for=(Exception,), retry_kwargs={'max_retries': 3, 'countdown': 5})
@shared_task(
autoretry_for=(Exception,), retry_kwargs={"max_retries": 3, "countdown": 5}
)
def sample_selenium_task():
driver = setup_webdriver(use_proxy=False, use_saved_session=False)
@ -18,27 +26,29 @@ def sample_selenium_task():
driver.close()
driver.quit()
# Sample task to scrape Google for search results based on a keyword
@shared_task(autoretry_for=(Exception,), retry_kwargs={'max_retries': 3, 'countdown': 5})
@shared_task(
autoretry_for=(Exception,), retry_kwargs={"max_retries": 3, "countdown": 5}
)
def simple_google_search():
driver = setup_webdriver(driver_type="firefox",
use_proxy=False, use_saved_session=False)
driver = setup_webdriver(
driver_type="firefox", use_proxy=False, use_saved_session=False
)
driver.get(f"https://google.com/")
google_search(driver, search_term="cat blog posts")
# Count number of Google search results
search_items = get_elements(
driver, "xpath", '//*[@id="search"]/div[1]/div[1]/*')
search_items = get_elements(driver, "xpath", '//*[@id="search"]/div[1]/div[1]/*')
for item in search_items:
title = item.find_element(By.TAG_NAME, 'h3').text
link = item.find_element(By.TAG_NAME, 'a').get_attribute('href')
title = item.find_element(By.TAG_NAME, "h3").text
link = item.find_element(By.TAG_NAME, "a").get_attribute("href")
create_search_result.apply_async(
kwargs={"title": title, "link": link})
create_search_result.apply_async(kwargs={"title": title, "link": link})
driver.close()
driver.quit()