Never use except exception it's a bad idea
This commit is contained in:
parent
5cb5bcad23
commit
febb7556cf
1 changed files with 6 additions and 5 deletions
11
bot.py
11
bot.py
|
@ -3,7 +3,7 @@ from selenium import webdriver
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException
|
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException, TimeoutException
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import time
|
import time
|
||||||
import disnake
|
import disnake
|
||||||
|
@ -46,23 +46,24 @@ def play_video(videourl):
|
||||||
elem = WebDriverWait(driver, 8, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button"))
|
elem = WebDriverWait(driver, 8, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button"))
|
||||||
sleep(1)
|
sleep(1)
|
||||||
elem.send_keys(Keys.RETURN)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception as e:
|
except (NoSuchElementException,TimeoutException) as e:
|
||||||
print(e)
|
print(e)
|
||||||
return #if this errors there is no fullscreen options, such as playlists, so skip the link
|
return #if this errors there is no fullscreen options, such as playlists, so skip the link
|
||||||
try:
|
try:
|
||||||
elem = driver.find_element(By.XPATH, '//button[@data-tooltip-target-id="ytp-autonav-toggle-button"][@aria-label="Autoplay is on"]')
|
elem = driver.find_element(By.XPATH, '//button[@data-tooltip-target-id="ytp-autonav-toggle-button"][@aria-label="Autoplay is on"]')
|
||||||
elem.send_keys(Keys.RETURN)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception:
|
except (NoSuchElementException,ElementNotVisibleException,TimeoutException):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
elem = WebDriverWait(driver, 5, 0.2, (NoSuchElementException,ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]'))
|
elem = WebDriverWait(driver, 5, 0.2, (NoSuchElementException,ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]'))
|
||||||
elem.send_keys(Keys.RETURN)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception as e:
|
except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e:
|
||||||
print(e)
|
print(e)
|
||||||
try:
|
try:
|
||||||
elem = WebDriverWait(driver, (float(os.getenv("MAX_MIN")) * 60), 1, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-endscreen").is_displayed())
|
elem = WebDriverWait(driver, (float(os.getenv("MAX_MIN")) * 60), 1, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-endscreen").is_displayed())
|
||||||
except Exception as e:
|
except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
sleep(1)
|
||||||
return #same as above
|
return #same as above
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue