Skip to content
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

Support For Python 3.11 #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@ dmypy.json
.vscode/
.temp/
.logs/
.idea/
.idea/

.venv/
19 changes: 10 additions & 9 deletions loconotion/modules/conditions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from selenium.webdriver.common.by import By

log = logging.getLogger(f"loconotion.{__name__}")

Expand All @@ -11,15 +12,15 @@ def __init__(self):

def __call__(self, driver):
notion_presence = len(
driver.find_elements_by_class_name("notion-presence-container")
driver.find_elements(By.CLASS_NAME, "notion-presence-container")
)
if (notion_presence):
unknown_blocks = len(driver.find_elements_by_class_name("notion-unknown-block"))
loading_spinners = len(driver.find_elements_by_class_name("loading-spinner"))
scrollers = driver.find_elements_by_class_name("notion-scroller")
unknown_blocks = len(driver.find_elements(By.CLASS_NAME, "notion-unknown-block"))
loading_spinners = len(driver.find_elements(By.CLASS_NAME, "loading-spinner"))
scrollers = driver.find_elements(By.CLASS_NAME, "notion-scroller")
scrollers_with_children = [];
for scroller in scrollers:
children = len(scroller.find_elements_by_tag_name("div"))
children = len(scroller.find_elements(By.TAG_NAME, "div"))
if children > 0:
scrollers_with_children.append(scroller)
source_changed = self.previous_page_source != driver.page_source
Expand Down Expand Up @@ -48,14 +49,14 @@ def __init__(self, toggle_block):
self.toggle_block = toggle_block

def __call__(self, driver):
toggle_content = self.toggle_block.find_element_by_css_selector("div:not([style]")
toggle_content = self.toggle_block.find_element(By.CSS_SELECTOR,"div:not([style]")
if toggle_content:
content_children = len(toggle_content.find_elements_by_tag_name("div"))
content_children = len(toggle_content.find_elements(By.TAG_NAME, "div"))
unknown_children = len(
toggle_content.find_elements_by_class_name("notion-unknown-block")
toggle_content.find_elements(By.CLASS_NAME, "notion-unknown-block")
)
is_loading = len(
self.toggle_block.find_elements_by_class_name("loading-spinner")
self.toggle_block.find_elements(By.CLASS_NAME, "loading-spinner")
)
log.debug(
f"Waiting for toggle block to load"
Expand Down
18 changes: 10 additions & 8 deletions loconotion/modules/notionparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
sys.exit(1)

from .conditions import notion_page_loaded, toggle_block_has_opened
from selenium.webdriver.common.by import By


class Parser:
Expand Down Expand Up @@ -238,11 +239,10 @@ def init_chromedriver(self):
chrome_options.add_argument("--log-level=3")
chrome_options.add_argument("--silent")
chrome_options.add_argument("--disable-logging")

# removes the 'DevTools listening' log message
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
return webdriver.Chrome(
executable_path=str(chromedriver_path),
service_log_path=str(logs_path),
options=chrome_options,
)

Expand Down Expand Up @@ -323,18 +323,20 @@ def open_toggle_blocks(self, timeout: int, exclude=[]):
Opening toggles is needed for hooking up our custom toggle logic afterwards.
"""
opened_toggles = exclude
toggle_blocks = self.driver.find_elements_by_class_name("notion-toggle-block")
toggle_blocks = self.driver.find_elements(By.CLASS_NAME, "notion-toggle-block")
toggle_blocks += self._get_title_toggle_blocks()
log.debug(f"Opening {len(toggle_blocks)} new toggle blocks in the page")
for toggle_block in toggle_blocks:
if toggle_block not in opened_toggles:
toggle_button = toggle_block.find_element_by_css_selector(
toggle_button = toggle_block.find_element(By.CSS_SELECTOR,
"div[role=button]"
)
# check if the toggle is already open by the direction of its arrow
is_toggled = "(180deg)" in (
toggle_button.find_element_by_tag_name("svg").get_attribute("style")
toggle_button.find_element(By.TAG_NAME,"svg").get_attribute("style")

)

if not is_toggled:
# click on it, then wait until all elements are displayed
self.driver.execute_script("arguments[0].click();", toggle_button)
Expand All @@ -353,7 +355,7 @@ def open_toggle_blocks(self, timeout: int, exclude=[]):

# after all toggles have been opened, check the page again to see if
# any toggle block had nested toggle blocks inside them
new_toggle_blocks = self.driver.find_elements_by_class_name(
new_toggle_blocks = self.driver.find_elements(By.CLASS_NAME,
"notion-toggle-block"
)
new_toggle_blocks += self._get_title_toggle_blocks()
Expand All @@ -367,11 +369,11 @@ def _get_title_toggle_blocks(self):
title_toggle_blocks = []
header_types = ["header", "sub_header", "sub_sub_header"]
for header_type in header_types:
title_blocks = self.driver.find_elements_by_class_name(
title_blocks = self.driver.find_elements(By.CLASS_NAME,
f"notion-selectable.notion-{header_type}-block"
)
for block in title_blocks:
toggle_buttons = block.find_elements_by_css_selector("div[role=button]")
toggle_buttons = block.find_elements(By.CSS_SELECTOR, "div[role=button]")
if len(toggle_buttons) > 0:
title_toggle_blocks.append(block)
return title_toggle_blocks
Expand Down
Loading