Пример #1
0
def get_quotes() -> None:
    driver.get("https://www.brainyquote.com/quote_of_the_day")
    quotes: Dict[str, str] = {}
    title: str
    text: str

    scroll_down(driver)
    quotes["Quote of the day"] = check_xpath_element(
        driver, bq_day_quote).text.replace("\n", " - ")

    scroll_down(driver)
    quotes["Love Quote of the day"] = check_xpath_element(
        driver, bq_love_quote).text.replace("\n", " - ")

    scroll_down(driver)
    quotes["Art Quote of the Day"] = check_xpath_element(
        driver, bq_art_quote).text.replace("\n", " - ")

    scroll_down(driver)
    quotes["Nature Quote of the Day"] = check_xpath_element(
        driver, bq_nature_quote).text.replace("\n", " - ")

    scroll_down(driver)
    quotes["Funny Quote Of the Day"] = check_xpath_element(
        driver, bq_funny_quote).text.replace("\n", " - ")

    quit_chromium(driver)

    for title, text in quotes.items():
        send_notification(title, text)
Пример #2
0
def get_weather(zip_code: str) -> None:
    RETURN_KEY: str = "\ue006"
    check_xpath_element(driver, google_search_label).send_keys("weather " + zip_code)
    check_xpath_element(driver, google_search_label).send_keys(RETURN_KEY)

    weather_type: str = "Weather: " + check_xpath_element(driver, google_weather_type_label).text.title() + "\n"

    high_temperature: str = check_xpath_element(driver, google_high_temp_label).text
    high_temperature = 'High Temperature: <font color="{}">{}</font>°F\n'.format(
        get_temp_color(int(high_temperature)), high_temperature)

    low_temperature: str = check_xpath_element(driver, google_low_temp_label).text
    low_temperature = 'Low Temperature: <font color="{}">{}</font>°F\n'.format(
        get_temp_color(int(low_temperature)), low_temperature)

    precipitation: str = check_xpath_element(driver, google_precipitation_label).text.split("%")[0]
    precipitation = 'Precipitation: <font color="{}">{}</font>%\n'.format("#5d96d4", precipitation)

    humidity: str = check_xpath_element(driver, google_humidity_label).text.split("%")[0]
    humidity = 'Humidity: <font color="{}">{}</font>%\n'.format("#28b319", humidity)

    wind: str = check_xpath_element(driver, google_wind_label).text.split(" ")[0]
    wind = 'Wind: <font color="{}">{}</font> MPH\n'.format("#d1fffd", wind)

    total_weather_report: str = weather_type + high_temperature + low_temperature + precipitation + humidity + wind
    send_notification(f"Weather Report from {zip_code}", total_weather_report)
Пример #3
0
def get_number_percent(star_rating: str) -> Union[int, float]:
    percent: Optional[webdriver.remote] = check_xpath_element(
        driver, star_rating)
    if percent is None:
        return 0
    else:
        return round(float(percent.text.split("%")[0]) / 100, 2)
Пример #4
0
def get_news_article(search: str) -> None:
    driver.get("https://www.google.com/")
    RETURN_KEY: str = "\ue006"
    check_xpath_element(driver, google_search_label).send_keys(search)
    check_xpath_element(driver, google_search_label).send_keys(RETURN_KEY)
    check_xpath_element(driver, google_news_tab).click()

    article_title: str = check_xpath_element(driver, google_first_article_name).text
    article_link: str = check_xpath_element(driver, google_first_article_link).get_attribute("href")
    news_articles[article_title] = article_link
Пример #5
0
def get_avg_rating(link: str) -> str:
    avg_rating: Optional[webdriver.remote] = check_xpath_element(
        driver, amazon_product_avg_rating)

    if avg_rating is None:
        print("Avg Rating " + link)
        return "-100"
    else:
        return avg_rating.text
Пример #6
0
def hover_over_star_ratings() -> Optional[bool]:
    try:
        ActionChains(driver).move_to_element(
            check_xpath_element(driver,
                                amazon_product_star_ratings_label)).perform()
    except AttributeError:
        return True
    except JavascriptException:
        return True
Пример #7
0
def check_number(web_driver, number: str) -> int:
    num: Optional[webdriver.remote] = check_xpath_element(web_driver, number)
    if num is None:
        return 0

    num: str = num.text.split(" ")[0]
    if "," in num:
        return int(num.replace(",", ""))
    else:
        return int(num)
Пример #8
0
def get_links(search: str) -> List[str]:
    print("Getting product links...")
    url_product_links: List[str] = []
    RETURN_KEY: str = "\ue006"
    driver.get("https://www.amazon.com/")
    check_xpath_element(driver, amazon_search_label).send_keys(search)
    check_xpath_element(driver, amazon_search_label).send_keys(RETURN_KEY)
    check_xpath_element(driver, amazon_four_star_button).click()
    scroll_down(driver)

    next_page: int = 1
    product_result: int = 1
    while True:
        anchor_tag_product: Optional[webdriver.remote] = check_xpath_element(
            driver, amazon_product_results.format(product_result))

        if anchor_tag_product is None:
            if next_page == max_num_of_pages:
                break
            else:
                product_result = 1
                next_page += 1
                check_xpath_element(driver, amazon_next_button).click()
                sleep(1)
                continue

        url_product: str = anchor_tag_product.get_attribute("href")
        print(url_product)

        if url_product not in url_product_links:
            url_product_links.append(url_product)
            if product_result % 4 == 0:
                scroll_down(driver, 235)
                print(len(url_product_links))

        product_result += 1

    print(len(url_product_links))
    return url_product_links
Пример #9
0
def get_product_price(link: str) -> str:
    product_cost: Optional[webdriver.remote] = check_xpath_element(
        driver, amazon_product_price_text)

    if product_cost is None:
        print("Product Price " + link)
        return "-100"
    else:
        product_price: str = product_cost.text

        if not product_price:
            return "-100"

        if "," in product_price:
            return product_price.replace(",", "")

    return product_price
Пример #10
0
def thumbs_up_the_post() -> None:
    if not check_post_reaction() and check_slack_name():
        check_xpath_element(driver, add_reaction_to_newest_post_button).click()
        check_xpath_element(driver, search_emoji_label).send_keys("thumbsup")
        check_xpath_element(driver, thumbs_up_button).click()

    if operating_system() == "Windows":
        path_to_screenshot: str = f"C:\\Users\\{user_name()}\\Desktop\\slack_post.png"
    else:
        path_to_screenshot: str = f"/Users/{user_name()}/Desktop/slack_post.png"
    driver.get_screenshot_as_file(path_to_screenshot)
    sleep(4)
    send_notification("Slack Update", "Post", path_to_screenshot)
    quit_chromium(driver)
    remove(path_to_screenshot)
Пример #11
0
def check_slack_name() -> bool:
    if check_xpath_element(driver, newest_post_slack_name).text == "USER":
        return True
    else:
        return False
Пример #12
0
def get_slack_update() -> None:
    driver.get("https://slack.com/signin")
    driver.set_window_size(1440, 700)

    check_xpath_element(driver,
                        slack_workspace_label).send_keys(slack_workspace)
    check_xpath_element(driver, slack_workspace_button).click()

    check_xpath_element(driver, username_label).send_keys(slack_email)
    check_xpath_element(driver, password_label).send_keys(slack_password)

    check_xpath_element(driver, sign_in_button).click()
    check_xpath_element(driver, channel_button).click()

    thumbs_up_the_post()