예제 #1
0
파일: walmart.py 프로젝트: fm407/nvidia-bot
    def __init__(self, notification_handler, headless=False):
        self.notification_handler = notification_handler
        self.url_list = []
        self.reserve = []
        if headless:
            enable_headless()
        options.add_argument(f"user-data-dir=.profile-wmrt")
        try:
            self.driver = webdriver.Chrome(executable_path=binary_path,
                                           options=options)
            self.wait = WebDriverWait(self.driver, 5)
        except Exception as e:
            log.error(e)
            exit(1)
        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    config = json.load(json_file)
                    self.username = config["username"]
                    self.password = config["password"]
                    self.civ = config["civ"]
                    self.url_groups = int(config["url_groups"])
                    self.walmart_website = config.get("walmart_website",
                                                      "walmart.com")
                    for x in range(self.url_groups):
                        self.url_list.append(config[f"url_list_{x+1}"])
                        self.reserve.append(float(config[f"reserve_{x+1}"]))
                    # assert isinstance(self.url_list, list)
                except Exception:
                    log.error(
                        "walmart_config.json file not formatted properly: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration"
                    )
                    exit(0)
        else:
            log.error(
                "No config file found, see here on how to fix this: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration"
            )
            exit(0)

        for key in WALMART_URLS.keys():
            WALMART_URLS[key] = WALMART_URLS[key].format(
                domain=self.walmart_website)
        self.driver.get(WALMART_URLS["BASE_URL"])
        log.info("Waiting for home page.")
        if self.driver.title in CAPTCHA_URL:
            self.defeat_captcha(self.driver.current_url)
        if self.is_logged_in():
            log.info("Already logged in")
        else:
            log.info("Lets log in.")
            log.info("Wait for Sign In page")
            self.login()
            self.notification_handler.send_notification(
                "Logged in and running", False)
            log.info("Waiting 5 seconds.")
            time.sleep(
                5
            )  # We can remove this once I get more info on the phone verification page.
예제 #2
0
    def __init__(self, notification_handler, headless=False):
        self.notification_handler = notification_handler
        if headless:
            enable_headless()
        options.add_argument(f"user-data-dir=.profile-amz")
        try:
            self.driver = webdriver.Chrome(executable_path=binary_path,
                                           options=options)
            self.wait = WebDriverWait(self.driver, 10)
        except SessionNotCreatedException as e:
            log.error(e)
            exit(1)
        except Exception as e:
            log.error(e)
        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    config = json.load(json_file)
                    self.username = config["username"]
                    self.password = config["password"]
                    self.asin_list = config["asin_list"]
                    self.reserve = float(config["reserve"])
                    self.amazon_website = config.get("amazon_website",
                                                     "smile.amazon.com")
                    assert isinstance(self.asin_list, list)
                except Exception:
                    log.error(
                        "amazon_config.json file not formatted properly: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration"
                    )
                    exit(0)
        else:
            log.error(
                "No config file found, see here on how to fix this: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration"
            )
            exit(0)

        for key in AMAZON_URLS.keys():
            AMAZON_URLS[key] = AMAZON_URLS[key].format(
                domain=self.amazon_website)
        self.driver.get(AMAZON_URLS["BASE_URL"])
        log.info("Waiting for home page.")
        self.check_if_captcha(self.wait_for_pages, HOME_PAGE_TITLES)

        if self.is_logged_in():
            log.info("Already logged in")
        else:
            log.info("Lets log in.")

            is_smile = "smile" in AMAZON_URLS["BASE_URL"]
            xpath = '//*[@id="ge-hello"]/div/span/a' if is_smile else '//*[@id="nav-link-accountList"]/div/span'
            selenium_utils.button_click_using_xpath(self.driver, xpath)
            log.info("Wait for Sign In page")
            self.check_if_captcha(self.wait_for_pages, SIGN_IN_TITLES)
            self.login()
            log.info("Waiting 15 seconds.")
            time.sleep(
                15
            )  # We can remove this once I get more info on the phone verification page.
예제 #3
0
    def create_driver(self):
        if self.setup_driver:

            if self.headless:
                enable_headless()

            # profile_amz = ".profile-amz"
            # # keep profile bloat in check
            # if os.path.isdir(profile_amz):
            #     os.remove(profile_amz)
            prefs = {
                "profile.password_manager_enabled": False,
                "credentials_enable_service": False,
            }
            if self.no_image:
                prefs["profile.managed_default_content_settings.images"] = 2
            else:
                prefs["profile.managed_default_content_settings.images"] = 0
            options.add_experimental_option("prefs", prefs)
            options.add_argument(f"user-data-dir=.profile-amz")
            if not self.slow_mode:
                options.set_capability("pageLoadStrategy", "none")

            self.setup_driver = False

        # Delete crashed, so restore pop-up doesn't happen
        path_to_prefs = os.path.join(
            os.path.dirname(os.path.abspath("__file__")),
            ".profile-amz",
            "Default",
            "Preferences",
        )
        try:
            with fileinput.FileInput(path_to_prefs, inplace=True) as file:
                for line in file:
                    print(line.replace("Crashed", "none"), end="")
        except FileNotFoundError:
            pass
        try:
            self.driver = webdriver.Chrome(executable_path=binary_path, options=options)
            self.wait = WebDriverWait(self.driver, 10)
            self.get_webdriver_pids()
        except Exception as e:
            log.error(e)
            log.warning(
                "You probably have a previous Chrome window open. You should close it"
            )
            return False

        return True
예제 #4
0
 def __init__(self, username, password, item_url, headless=False):
     self.notification_handler = NotificationHandler()
     if headless:
         enable_headless()
     h = hashlib.md5(item_url.encode()).hexdigest()
     options.add_argument(f"user-data-dir=.profile-amz-{h}")
     self.driver = webdriver.Chrome(executable_path=binary_path,
                                    options=options)
     self.wait = WebDriverWait(self.driver, 10)
     self.username = username
     self.password = password
     self.driver.get(BASE_URL)
     if self.is_logged_in():
         log.info("Already logged in")
     else:
         self.login()
         time.sleep(15)
예제 #5
0
    def __init__(self, headless=False):
        self.notification_handler = NotificationHandler()
        if headless:
            enable_headless()
        options.add_argument(f"user-data-dir=.profile-amz")
        self.driver = webdriver.Chrome(executable_path=binary_path,
                                       options=options)
        self.wait = WebDriverWait(self.driver, 10)
        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    config = json.load(json_file)
                    self.username = config["username"]
                    self.password = config["password"]
                    self.asin_list = config["asin_list"]
                    self.amazon_website = config.get("amazon_website",
                                                     "amazon.com")
                    assert isinstance(self.asin_list, list)
                except Exception:
                    raise InvalidAutoBuyConfigException(
                        "amazon_config.json file not formatted properly.")
        else:
            raise InvalidAutoBuyConfigException(
                "Missing amazon_config.json file.")

        for key in AMAZON_URLS.keys():
            AMAZON_URLS[key] = AMAZON_URLS[key].format(self.amazon_website)
        print(AMAZON_URLS)
        self.driver.get(AMAZON_URLS["BASE_URL"])
        log.info("Waiting for home page.")
        self.check_if_captcha(self.wait_for_pages, HOME_PAGE_TITLES)

        if self.is_logged_in():
            log.info("Already logged in")
        else:
            log.info("Lets log in.")
            selenium_utils.button_click_using_xpath(
                self.driver, '//*[@id="nav-link-accountList"]/div/span')
            log.info("Wait for Sign In page")
            self.check_if_captcha(self.wait_for_pages, SIGN_IN_TITLES)
            self.login()
            log.info("Waiting 15 seconds.")
            time.sleep(
                15
            )  # We can remove this once I get more info on the phone verification page.
예제 #6
0
    def __init__(
        self,
        notification_handler,
        headless=False,
        checkshipping=False,
        random_delay=False,
        detailed=False,
        used=False,
        single_shot=False,
        no_screenshots=False,
    ):
        self.notification_handler = notification_handler
        self.asin_list = []
        self.reserve = []
        self.checkshipping = checkshipping
        self.button_xpaths = BUTTON_XPATHS
        self.random_delay = random_delay
        self.detailed = detailed
        self.used = used
        self.single_shot = single_shot
        self.no_screenshots = no_screenshots
        self.start_time = time.time()
        self.start_time_atc = 0

        if not self.no_screenshots:
            if not os.path.exists("screenshots"):
                try:
                    os.makedirs("screenshots")
                except:
                    raise

        if not os.path.exists("html_saves"):
            try:
                os.makedirs("html_saves")
            except:
                raise

        if os.path.exists(CREDENTIAL_FILE):
            credential = load_encrypted_config(CREDENTIAL_FILE)
            self.username = credential["username"]
            self.password = credential["password"]
        else:
            log.info("No credential file found, let's make one")
            credential = self.await_credential_input()
            create_encrypted_config(credential, CREDENTIAL_FILE)
            self.username = credential["username"]
            self.password = credential["password"]

        if os.path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    config = json.load(json_file)
                    self.asin_groups = int(config["asin_groups"])
                    self.amazon_website = config.get("amazon_website",
                                                     "smile.amazon.com")
                    for x in range(self.asin_groups):
                        self.asin_list.append(config[f"asin_list_{x + 1}"])
                        self.reserve.append(float(config[f"reserve_{x + 1}"]))
                    # assert isinstance(self.asin_list, list)
                except Exception:
                    log.error(
                        "amazon_config.json file not formatted properly: https://github.com/Hari-Nagarajan/fairgame/wiki/Usage#json-configuration"
                    )
                    exit(0)
        else:
            log.error(
                "No config file found, see here on how to fix this: https://github.com/Hari-Nagarajan/fairgame/wiki/Usage#json-configuration"
            )
            exit(0)

        if headless:
            enable_headless()

        # profile_amz = ".profile-amz"
        # # keep profile bloat in check
        # if os.path.isdir(profile_amz):
        #     os.remove(profile_amz)
        options.add_argument(f"user-data-dir=.profile-amz")
        # options.page_load_strategy = "eager"

        try:
            self.driver = webdriver.Chrome(executable_path=binary_path,
                                           options=options)
            self.wait = WebDriverWait(self.driver, 10)
        except Exception as e:
            log.error(e)
            exit(1)

        for key in AMAZON_URLS.keys():
            AMAZON_URLS[key] = AMAZON_URLS[key].format(
                domain=self.amazon_website)
예제 #7
0
import time

from chromedriver_py import binary_path  # this will get you the path variable
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.expected_conditions import presence_of_element_located
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException

from notifications.notifications import NotificationHandler
from utils.logger import log
from utils.selenium_utils import options, enable_headless, wait_for_element

options.add_argument("user-data-dir=.profile-amz")

BASE_URL = "https://www.amazon.com/"
LOGIN_URL = "https://www.amazon.com/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_custrec_signin&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&"


class Amazon:
    def __init__(self, username, password, headless=False):
        self.notification_handler = NotificationHandler()
        if headless:
            enable_headless()
        self.driver = webdriver.Chrome(executable_path=binary_path, options=options)
        self.wait = WebDriverWait(self.driver, 10)
        self.username = username
        self.password = password
        self.driver.get(BASE_URL)