Repository: mxrch/GHunt
File: lib/photos.py (Python)

Code before:

	class element_has_substring_or_substring(object):
		"""An expectation for checking that an element has a particular css class.

		locator - used to find the element
		returns the WebElement once it has the particular css class
		"""
		def __init__(self, locator, substring1, substring2):
			self.locator = locator
			self.substring1 = substring1
			self.substring2 = substring2
			
		def __call__(self, driver):
			element = driver.find_element(*self.locator)   # Finding the referenced element
			if self.substring1 in element.text:
				return self.substring1
			elif self.substring2 in element.text:
				return self.substring2
			else:
				return False

	tmprinter = TMPrinter()
	chrome_options = Options()
	chrome_options.add_argument('--log-level=3')
	chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
	chrome_options.add_argument('--no-sandbox')
	if cfg["headless"]:
		chrome_options.add_argument("--headless")
		get_wsl_chrome_options_args()
	options = {
		'connection_timeout': None  # Never timeout, otherwise it floods errors
	}

	tmprinter.out("Starting browser...")

	driverpath = get_driverpath()
	driver = webdriver.Chrome(executable_path=driverpath, seleniumwire_options=options, options=chrome_options)
	wait = WebDriverWait(driver, 30)

	tmprinter.out("Setting cookies...")
	driver.get("https://get.google.com/robots.txt")
	for k,v in cookies.items():
		driver.add_cookie({'name': k, 'value': v})

	tmprinter.out('Fetching Google Photos "Profile photos" album...')
	driver.get(f"https://get.google.com/albumarchive/{gaiaID}/albums/profile-photos?hl=en")

	tmprinter.out('Fetching the Google Photos albums overview...')
	buttons = driver.find_elements(By.XPATH, "//button")
	for button in buttons:
		text = button.get_attribute('jsaction')

Review comment (suggestion):
Same case as my previous comment. This should be deleted. Otherwise, when using WSL or Windows, chrome will end up with `--no-sandbox --no-sandbox` as arguments.

Code after:

	class element_has_substring_or_substring(object):
		"""An expectation for checking that an element has a particular css class.

		locator - used to find the element
		returns the WebElement once it has the particular css class
		"""
		def __init__(self, locator, substring1, substring2):
			self.locator = locator
			self.substring1 = substring1
			self.substring2 = substring2
			
		def __call__(self, driver):
			element = driver.find_element(*self.locator)   # Finding the referenced element
			if self.substring1 in element.text:
				return self.substring1
			elif self.substring2 in element.text:
				return self.substring2
			else:
				return False

	tmprinter = TMPrinter()
	chrome_options = Options()
	chrome_options.add_argument('--log-level=3')
	chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
	if cfg["headless"]:
		get_chrome_options_args()
	options = {
		'connection_timeout': None  # Never timeout, otherwise it floods errors
	}

	tmprinter.out("Starting browser...")

	driverpath = get_driverpath()
	driver = webdriver.Chrome(executable_path=driverpath, seleniumwire_options=options, options=chrome_options)
	wait = WebDriverWait(driver, 30)

	tmprinter.out("Setting cookies...")
	driver.get("https://get.google.com/robots.txt")
	for k,v in cookies.items():
		driver.add_cookie({'name': k, 'value': v})

	tmprinter.out('Fetching Google Photos "Profile photos" album...')
	driver.get(f"https://get.google.com/albumarchive/{gaiaID}/albums/profile-photos?hl=en")

	tmprinter.out('Fetching the Google Photos albums overview...')
	buttons = driver.find_elements(By.XPATH, "//button")
	for button in buttons:
		text = button.get_attribute('jsaction')
		if text and 'touchcancel' in text:
			button.click()