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

Code before:
            delta = relativedelta(years=nb)
        else:
            delta = relativedelta()
        return (datetime.today() - delta).replace(microsecond=0, second=0)

    tmprinter = TMPrinter()

    base_url = f"https://www.google.com/maps/contrib/{gaiaID}/reviews?hl=en"
    print(f"\nGoogle Maps : {base_url.replace('?hl=en', '')}")

    tmprinter.out("Initial request...")

    req = client.get(base_url)
    source = req.text

    data = source.split(';window.APP_INITIALIZATION_STATE=')[1].split(';window.APP_FLAGS')[0].replace("\\", "")

    if "/maps/reviews/data" not in data:
        tmprinter.out("")
        print("=> No reviews")
        return False
        
    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, 15)

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

    tmprinter.out("Fetching reviews page...")
    driver.get(base_url)
    
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.section-scrollbox')))
    scrollbox = driver.find_element_by_css_selector('div.section-scrollbox')

    tab_info = driver.find_elements_by_css_selector('div.section-tab-info')

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

Code after:
            delta = relativedelta(years=nb)
        else:
            delta = relativedelta()
        return (datetime.today() - delta).replace(microsecond=0, second=0)

    tmprinter = TMPrinter()

    base_url = f"https://www.google.com/maps/contrib/{gaiaID}/reviews?hl=en"
    print(f"\nGoogle Maps : {base_url.replace('?hl=en', '')}")

    tmprinter.out("Initial request...")

    req = client.get(base_url)
    source = req.text

    data = source.split(';window.APP_INITIALIZATION_STATE=')[1].split(';window.APP_FLAGS')[0].replace("\\", "")

    if "/maps/reviews/data" not in data:
        tmprinter.out("")
        print("=> No reviews")
        return False
        
    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, 15)

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

    tmprinter.out("Fetching reviews page...")
    driver.get(base_url)
    
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.section-scrollbox')))
    scrollbox = driver.find_element_by_css_selector('div.section-scrollbox')

    tab_info = driver.find_elements_by_css_selector('div.section-tab-info')
    if tab_info:
        scroll_max = sum([int(x) for x in tab_info[0].text.split() if x.isdigit()])