from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from time import sleep

class Admin:
    def __init__(self, base, cookie):
        self.base = base
        self.cookie = cookie

    def visit(self, path):
        print(f"Started crawling {self.base + path}")
        try:
            options = Options()
            options.add_argument("--headless")
            options.add_argument("--verbose")
            options.binary = "/usr/bin/firefox"
            browser = Firefox(options=options)
            browser.set_page_load_timeout(30)
            browser.set_script_timeout(30)
            browser.get(self.base + "/cookies") # just to get the browser on the site, does not exist
            for name, value in self.cookie.items():
                browser.add_cookie({"name": name, "value": value})
            browser.get(self.base + path)
            sleep(5)
        except Exception as e:
            print(repr(e))

        print(f"Finished crawling {self.base + path}")
