From 97fa76b76795b536351c73792b57da361b48f91e Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Wed, 17 May 2023 18:46:17 +0200 Subject: [PATCH] Add files via upload --- content/is_english_content.json | 3 +++ content/is_english_content.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 content/is_english_content.json create mode 100644 content/is_english_content.py diff --git a/content/is_english_content.json b/content/is_english_content.json new file mode 100644 index 0000000..c1df089 --- /dev/null +++ b/content/is_english_content.json @@ -0,0 +1,3 @@ +{ + "search_for_string": "en-us-gb.png" +} \ No newline at end of file diff --git a/content/is_english_content.py b/content/is_english_content.py new file mode 100644 index 0000000..a7efe3b --- /dev/null +++ b/content/is_english_content.py @@ -0,0 +1,32 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import os +import json + + +def is_english_content( + driver: webdriver.firefox.webdriver.WebDriver, content_id: int +) -> bool: + string_json_path: str = os.path.join("content", "is_english_content.json") + + with open(string_json_path, "r") as file: + string_dict = json.load(file) + + found_element_list = driver.find_elements(By.TAG_NAME, "div") + + for element in found_element_list: + dtab = str(element.get_dom_attribute("data-table")) + duid = str(element.get_dom_attribute("data-uid")) + dtyp = str(element.get_dom_attribute("data-ctype")) + if ( + (dtab == "tt_content") + and (duid == str(content_id)) + and (dtyp == "textmedia") + ): + sub_element_list = element.find_elements(By.TAG_NAME, "img") + for sub_element in sub_element_list: + img_name = str(sub_element.get_dom_attribute("src")) + if img_name.endswith(string_dict["search_for_string"]): + return True + + return False