Ejemplo n.º 1
0
def main():
    war = War()
    try:
        war.run()
    except Exception, error: 
        log.debug('Exception catch: %s' %error)
        war.terminate()
Ejemplo n.º 2
0
 def load_map(self, map_file='maps/%s.png' %MAP):
     log.debug('Loading map: %s' %map_file)
     self.map = pygame.image.load(map_file)
     self.map = pygame.transform.scale(self.map, (self.sizeX, self.sizeY))     
     with open('maps/%s.json' %MAP, 'r') as json_file:
         self.data = json.load(json_file)
     log.debug(self.data)
Ejemplo n.º 3
0
async def on_ready():
    print("Logged in as:\n{}/{}#{}\n----------".format(bot.user.id, bot.user.name, bot.user.discriminator))
    print("Bot version: {}\nAuthor(s): {}\nCode name: {}\nBuild date: {}".format(BUILD_VERSION, BUILD_AUTHORS, BUILD_CODENAME, BUILD_DATE))
    log.debug("Debugging enabled!")
    await set_default_status()
    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as e:
            log.error("Failed to load extension {}\n{}: {}".format(extension, type(e).__name__, e))
    if config.enableMal:
        try:
            bot.load_extension("commands.myanimelist")
            log.info("The MyAnimeList module has been enabled!")
        except Exception as e:
            log.error("Failed to load the MyAnimeList module\n{}: {}".format(type(e).__name__, e))
    if config.enableOsu:
        log.info("The osu! module has been enabled in the config!")
    if config._dbots_token:
        log.info("Updating DBots Statistics...")
        r = requests.post("https://bots.discord.pw/api/bots/{}/stats".format(bot.user.id), json={"server_count":len(bot.servers)}, headers={"Authorization":config._dbots_token})
        if r.status_code == "200":
            log.info("Discord Bots Server count updated.")
        elif r.status_code == "401":
            log.error("An error occurred while trying to update the server count!")
    load_opus_lib()
Ejemplo n.º 4
0
    def __init__(self, skin):

        disp_no = os.getenv("DISPLAY")
        self.skin=skin
        self.pygame=pygame
        self.w=480
        self.h=320

        os.putenv('SDL_FBDEV', '/dev/fb1')
        os.putenv('SDL_MOUSEDRV', 'TSLIB')
        os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
        self.pygame.display.init()
        self.pygame.mouse.set_visible(True)
        size = [self.w, self.h]
        log.debug("Framebuffer size: %d x %d" % (size[0], size[1]))

 
        
        self.screen = self.pygame.display.set_mode(size, self.pygame.FULLSCREEN)
        log.debug("Ready for update")
        
        self.screen.fill((0, 0, 0))        
        self.pygame.mouse.set_visible(0)
        # Initialise font support
        self.pygame.font.init()
        # Render the screen
        self.pygame.display.update()
Ejemplo n.º 5
0
 def __init__(self, sizeX=800, sizeY=600, sizeFont=12):
     log.debug('Creating War object')
     self.world = ''
     pygame.init()
     pygame.display.set_caption('%s - %s %s' %(NAME, COMPANY, VERSION))
     self.sizeX = sizeX
     self.sizeY = sizeY
     self.sizeF = sizeFont
     self.screen = pygame.display.set_mode((self.sizeX, self.sizeY))                
Ejemplo n.º 6
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            log.debug("Loaded opus lib \"{}\"".format(opus_lib))
            return
        except OSError:
            pass
    log.critical("Could not load an opus lib. Tried {}".format(", ".join(opus_libs)))
    os._exit(1)
Ejemplo n.º 7
0
async def blacklist(ctx, id:int, *, reason:str):
    """Blacklists a user"""
    await ctx.channel.trigger_typing()
    user = discord.utils.get(list(bot.get_all_members()), id=id)
    if user is None:
        await ctx.send("Could not find a user with an id of `{}`".format(id))
        return
    if getblacklistentry(id) != None:
        await ctx.send("`{}` is already blacklisted".format(user))
        return
    blacklistuser(id, user.name, user.discriminator, reason)
    await ctx.send("Blacklisted `{}` Reason: `{}`".format(user, reason))
    try:
        await user.send("You have been blacklisted from the bot by `{}` Reason: `{}`".format(ctx.author, reason))
    except:
        log.debug("Couldn't send a message to a user with an ID of \"{}\"".format(id))
    await channel_logger.log_to_channel(":warning: `{}` blacklisted `{}`/`{}` Reason: `{}`".format(ctx.author, id, user, reason))
Ejemplo n.º 8
0
async def unblacklist(ctx, id:int):
    """Unblacklists a user"""
    entry = getblacklistentry(id)
    if entry is None:
        await ctx.send("No blacklisted user can be found with an id of `{}`".format(id))
        return
    try:
        unblacklistuser(id)
    except:
        await ctx.send("No blacklisted user can be found with an id of `{}`".format(id)) # Don't ask pls
        return
    await ctx.send("Successfully unblacklisted `{}#{}`".format(entry.get("name"), entry.get("discrim")))
    try:
        await discord.User(id=id).send("You have been unblacklisted from the bot by `{}`".format(ctx.author))
    except:
        log.debug("Couldn't send a message to a user with an ID of \"{}\"".format(id))
    await channel_logger.log_to_channel(":warning: `{}` unblacklisted `{}`/`{}#{}`".format(ctx.author, id, entry.get("name"), entry.get("discrim")))
Ejemplo n.º 9
0
 def run(self):       
     self.load_map()
     self.create_objects()
     self.world.set_player_country()
                             
     #        
     # Display status window
     #
     self.print_status(self.sizeX/5, self.sizeY/3)
     self.screen.blit(self.map, (0,0))
     while True:            
         event = pygame.event.wait()
         if event.type == pygame.QUIT:
             log.debug('QUIT')
             self.terminate()
         elif event.type == MOUSEBUTTONUP:
             log.debug('MOUSEBUTTONUP')
             mouseX, mouseY = event.pos
             clicked_color = self.map.get_at((mouseX, mouseY))
             log.debug('Clicked color: %s' %clicked_color)
             #
             # Analyze if player clicked a neighbor, his country or nothing important 
             #
             self.world.click(clicked_color)
         
         self.print_status(self.sizeX/5, self.sizeY/3)
         self.screen.blit(self.map, (0,0))
         pygame.display.update()
         
         self.world.msg = list()       
Ejemplo n.º 10
0
    def selenium_checkout(self):
        log.info("Checking out.")
        autobuy_btns = autobuy_locale_btns[self.locale]
        params = {"token": self.access_token}
        url = furl(DIGITAL_RIVER_CHECKOUT_URL).set(params)
        self.driver.get(url.url)
        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['checkout']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["checkout"])

        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()
        log.debug(f"Entering security code to 'cardSecurityCode'")
        security_code = selenium_utils.wait_for_element(
            self.driver, "cardSecurityCode")
        security_code.send_keys(self.cvv)
        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()

        try:
            log.debug(
                f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
            )
            selenium_utils.wait_for_page(
                self.driver,
                PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        except TimeoutException:
            log.debug("Address validation required?")
            self.address_validation_page()

        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)

        if not self.test:
            log.info("F this captcha lmao. Submitting cart.")
            self.submit_cart()
        else:
            log.info("Test complete. No actual purchase was made.")
Ejemplo n.º 11
0
    def check_stock(self, asin, reserve_min, reserve_max, retry=0):
        if retry > DEFAULT_MAX_ATC_TRIES:
            log.info("max add to cart retries hit, returning to asin check")
            return False
        if self.checkshipping:
            if self.used:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin)
            else:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin + "/ref=olp_f_new&f_new=true")
        else:
            if self.used:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin + "/f_freeShipping=on")
            else:
                f = furl(
                    AMAZON_URLS["OFFER_URL"]
                    + asin
                    + "/ref=olp_f_new&f_new=true&f_freeShipping=on"
                )
        fail_counter = 0
        presence.searching_update()

        while True:
            try:
                self.get_page(f.url)
                break
            except Exception:
                fail_counter += 1
                log.error(f"Failed to load the offer URL {fail_counter} times.")
                if fail_counter < DEFAULT_MAX_URL_FAIL:
                    log.error(
                        f"WebDriver will restart if it fails {DEFAULT_MAX_URL_FAIL} times. Retrying now..."
                    )
                    time.sleep(3)
                else:
                    log.info(
                        "Attempting to delete and recreate current chrome instance"
                    )
                    if not self.delete_driver():
                        log.error("Failed to delete chrome processes")
                        log.error("Please restart bot")
                        self.send_notification(
                            message="Bot Failed, please restart bot",
                            page_name="Bot Failed",
                            take_screenshot=False,
                        )
                        raise RuntimeError("Failed to restart bot")
                    elif not self.create_driver():
                        log.error("Failed to recreate webdriver processes")
                        log.error("Please restart bot")
                        self.send_notification(
                            message="Bot Failed, please restart bot",
                            page_name="Bot Failed",
                            take_screenshot=False,
                        )
                        raise RuntimeError("Failed to restart bot")
                    else:  # deleted driver and recreated it succesfully
                        log.info(
                            "WebDriver recreated successfully. Returning back to stock check"
                        )
                        return False

        timeout = self.get_timeout()
        while True:
            atc_buttons = self.driver.find_elements_by_xpath(
                '//*[@name="submit.addToCart"]'
            )
            if atc_buttons:
                # Early out if we found buttons
                break

            test = None
            try:
                test = self.driver.find_element_by_xpath(
                    '//*[@id="olpOfferList"]/div/p'
                )
            except exceptions.NoSuchElementException:
                pass

            if test and (test.text in NO_SELLERS):
                return False
            if time.time() > timeout:
                log.info(f"failed to load page for {asin}, going to next ASIN")
                return False

        timeout = self.get_timeout()
        while True:
            prices = self.driver.find_elements_by_xpath(
                '//*[@class="a-size-large a-color-price olpOfferPrice a-text-bold"]'
            )
            if prices:
                break
            if time.time() > timeout:
                log.info(f"failed to load prices for {asin}, going to next ASIN")
                return False
        shipping = []
        if self.checkshipping:
            timeout = self.get_timeout()
            while True:
                shipping = self.driver.find_elements_by_xpath(
                    '//*[@class="a-color-secondary"]'
                )
                if shipping:
                    break
                if time.time() > timeout:
                    log.info(f"failed to load shipping for {asin}, going to next ASIN")
                    return False

        in_stock = False

        for idx, atc_button in enumerate(atc_buttons):
            try:
                price = parse_price(prices[idx].text)
            except IndexError:
                log.debug("Price index error")
                return False
            try:
                if self.checkshipping:
                    if SHIPPING_ONLY_IF in shipping[idx].text:
                        ship_price = parse_price("0")
                    else:
                        ship_price = parse_price(shipping[idx].text)
                else:
                    ship_price = parse_price("0")
            except IndexError:
                log.debug("shipping index error")
                return False
            ship_float = ship_price.amount
            price_float = price.amount
            if price_float is None:
                return False
            if ship_float is None or not self.checkshipping:
                ship_float = 0

            if (
                (ship_float + price_float) <= reserve_max
                or math.isclose((price_float + ship_float), reserve_max, abs_tol=0.01)
            ) and (
                (ship_float + price_float) >= reserve_min
                or math.isclose((price_float + ship_float), reserve_min, abs_tol=0.01)
            ):
                log.info("Item in stock and in reserve range!")
                log.info("clicking add to cart")
                self.notification_handler.play_notify_sound()
                if self.detailed:
                    self.send_notification(
                        message=f"Found Stock ASIN:{asin}",
                        page_name="Stock Alert",
                        take_screenshot=self.take_screenshots,
                    )

                presence.buy_update()
                current_title = self.driver.title
                # log.info(f"current page title is {current_title}")
                try:
                    atc_button.click()
                except IndexError:
                    log.debug("Index Error")
                    return False
                self.wait_for_page_change(current_title)
                # log.info(f"page title is {self.driver.title}")
                if self.driver.title in SHOPING_CART_TITLES:
                    return True
                else:
                    log.info("did not add to cart, trying again")
                    log.debug(f"failed title was {self.driver.title}")
                    self.send_notification(
                        "Failed Add to Cart", "failed-atc", self.take_screenshots
                    )
                    self.save_page_source("failed-atc")
                    in_stock = self.check_stock(
                        asin=asin,
                        reserve_max=reserve_max,
                        reserve_min=reserve_min,
                        retry=retry + 1,
                    )
        return in_stock
Ejemplo n.º 12
0
async def on_ready():
    print("Connected!\n")
    print("Logged in as:\n{}/{}#{}\n----------".format(bot.user.id,
                                                       bot.user.name,
                                                       bot.user.discriminator))
    print(
        "Bot version: {}\nAuthor(s): {}\nCode name: {}\nBuild date: {}".format(
            BUILD_VERSION, BUILD_AUTHORS, BUILD_CODENAME, BUILD_DATE))
    log.debug("Debugging enabled!")
    if config.enable_default_status:
        await set_default_status()
    else:
        await bot.change_presence(activity=discord.Activity(
            name="code failure", type=discord.ActivityType.watching),
                                  status=discord.Status.dnd)
    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as e:
            log.error("Failed to load extension {}\n{}: {}".format(
                extension,
                type(e).__name__, traceback.format_exc()))
    if os.path.isdir("data/music"):
        try:
            bot.cogs["Music"].clear_data()
            log.info("The music cache has been cleared!")
        except:
            log.warning("Failed to clear the music cache!")
    if config.enableMal:
        try:
            bot.load_extension("commands.myanimelist")
            log.info("The MyAnimeList module has been enabled!")
        except Exception as e:
            log.error("Failed to load the MyAnimeList module\n{}: {}".format(
                type(e).__name__, e))
    if config.enableOsu:
        log.info("The osu! module has been enabled in the config!")
    if config._dbots_token:
        log.info("Updating DBots Statistics...")
        try:
            r = requests.post(
                "https://bots.discord.pw/api/bots/{}/stats".format(
                    bot.user.id),
                json={"server_count": len(bot.guilds)},
                headers={"Authorization": config._dbots_token},
                timeout=5)
            if r.status_code == "200":
                log.info("Discord Bots guild count updated.")
            elif r.status_code == "401":
                log.error(
                    "An error occurred while trying to update the guild count!"
                )
        except requests.exceptions.Timeout:
            log.error("Failed to update the guild count: request timed out.")
    if config._carbonitex_key:
        log.info("Updating Carbonitex Statistics...")
        payload = {
            "key": config._carbonitex_key,
            "guildcount": len(bot.guilds),
            "botname": bot.user.name,
            "logoid": bot.user.avatar_url
        }
        owner = discord.utils.get(list(bot.get_all_members()),
                                  id=config.owner_id)
        if owner is not None:
            payload["ownername"] = owner.name
        try:
            r = requests.post(
                "https://www.carbonitex.net/discord/data/botdata.php",
                json=payload,
                timeout=5)
            if r.text == "1 - Success":
                log.info("Carbonitex stats updated")
            else:
                log.error(
                    "Failed to update the carbonitex stats, double check the key in the config!"
                )
        except requests.exceptions.Timeout:
            log.error(
                "Failed to update the carbonitex stats: request timed out")

    if config.enableSteam:
        if not config._steamAPIKey:
            log.warning(
                "The steam module was enabled but no steam web api key was specified, disabling..."
            )
        else:
            bot.load_extension("commands.steam")
            log.info("The steam module has been enabled!")
Ejemplo n.º 13
0
    def __init__(self, gpu, locale="en_us"):
        self.product_ids = set([])
        self.cli_locale = locale.lower()
        self.locale = self.map_locales()
        self.session = requests.Session()
        self.gpu = gpu
        self.enabled = True
        self.auto_buy_enabled = False

        self.gpu_long_name = GPU_DISPLAY_NAMES[gpu]

        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                self.config = json.load(json_file)
                if self.has_valid_creds():
                    self.nvidia_login = self.config["NVIDIA_LOGIN"]
                    self.nvidia_password = self.config["NVIDIA_PASSWORD"]
                    self.auto_buy_enabled = self.config["FULL_AUTOBUY"]
                    self.cvv = self.config.get("CVV")
        else:
            log.info("No Autobuy creds found.")

        # Disable auto_buy_enabled if the user does not provide a bool.
        if type(self.auto_buy_enabled) != bool:
            self.auto_buy_enabled = False

        adapter = HTTPAdapter(max_retries=Retry(
            total=10,
            backoff_factor=1,
            status_forcelist=[429, 500, 502, 503, 504],
            method_whitelist=["HEAD", "GET", "OPTIONS"],
        ))
        self.session.mount("https://", adapter)
        self.session.mount("http://", adapter)
        self.notification_handler = NotificationHandler()

        log.info("Opening Webdriver")
        self.driver = webdriver.Chrome(executable_path=binary_path,
                                       options=options,
                                       chrome_options=chrome_options)
        self.sign_in()
        selenium_utils.add_cookies_to_session_from_driver(
            self.driver, self.session)
        log.info("Adding driver cookies to session")

        log.info("Getting product IDs")
        self.access_token = self.get_nividia_access_token()
        self.payment_option = self.get_payment_options()
        if not self.payment_option.get("id") or not self.cvv:
            log.error(
                "No payment option on account or missing CVV. Disable Autobuy")
            self.auto_buy_enabled = False
        else:
            log.debug(self.payment_option)
            self.ext_ip = self.get_ext_ip()

        if not self.auto_buy_enabled:
            log.info("Closing webdriver")
            self.driver.close()

        self.get_product_ids()
        while len(self.product_ids) == 0:
            log.info(
                f"We have no product IDs for {self.gpu_long_name}, retrying until we get a product ID"
            )
            self.get_product_ids()
            sleep(5)
Ejemplo n.º 14
0
 def __del__(self):
     log.debug('StoreClient::__del__()')
     if self.http:
         self.http.close()
Ejemplo n.º 15
0
    def __init__(self):
        log.info("Initializing Apprise handler")
        self.apb = apprise.Apprise()

        if path.exists(APPRISE_CONFIG_PATH):
            with open(APPRISE_CONFIG_PATH) as json_file:
                configs = json.load(json_file)
                for config in configs:
                    self.apb.add(config["url"])
            self.queue = queue.Queue()
            self.start_worker()
            self.enabled = True
        else:
            self.enabled = False
            log.debug("No Apprise config found.")

        log.info("Initializing other notification handlers")
        self.audio_handler = AudioHandler()
        self.twilio_handler = TwilioHandler()  # Deprecate soon
        self.discord_handler = DiscordHandler()  # Deprecate soon
        self.join_handler = JoinHandler()  # Deprecate soon
        self.telegram_handler = TelegramHandler()  # Deprecate soon
        self.slack_handler = SlackHandler()  # Deprecate soon

        deprecation_message = "The standalone {notification} handler will be deprecated soon, please delete your {notification}_config.json and add the equivalent apprise url: '{apprise_url}' to 'config/apprise_config.json'"
        if self.slack_handler.enabled:
            slack_apprise_url = self.slack_handler.generate_apprise_url()
            log.warning(
                deprecation_message.format(notification="slack",
                                           apprise_url=slack_apprise_url))
            self.apb.add(slack_apprise_url)

        if self.twilio_handler.enabled:
            twilio_apprise_url = self.twilio_handler.generate_apprise_url()
            log.warning(
                deprecation_message.format(notification="twilio",
                                           apprise_url=twilio_apprise_url))
            self.apb.add(twilio_apprise_url)

        if self.telegram_handler.enabled:
            telegram_apprise_url = self.telegram_handler.generate_apprise_url()
            log.warning(
                deprecation_message.format(notification="telegram",
                                           apprise_url=telegram_apprise_url))
            self.apb.add(telegram_apprise_url)

        if self.join_handler.enabled:
            join_apprise_url = self.join_handler.generate_apprise_url()
            log.warning(
                deprecation_message.format(notification="join",
                                           apprise_url=join_apprise_url))
            self.apb.add(join_apprise_url)

        if self.discord_handler.enabled:
            discord_apprise_url = self.discord_handler.generate_apprise_url()
            log.warning(
                deprecation_message.format(notification="discord",
                                           apprise_url=discord_apprise_url))
            self.apb.add(discord_apprise_url)

        enabled_handlers = self.get_enabled_handlers()
        log.info(f"Enabled Handlers: {enabled_handlers}")
        if len(enabled_handlers) > 0:
            self.executor = ThreadPoolExecutor(
                max_workers=len(enabled_handlers))
Ejemplo n.º 16
0
 def onStartWork(self):
     log.debug('[onStartWork] %s' % self.getDisplayName())
     return True
Ejemplo n.º 17
0
 def access_token(self):
     if datetime.today().timestamp() >= self.token_data.get("expires_at"):
         log.debug("Access token expired")
         self.token_data = self.get_nvidia_access_token()
     return self.token_data["access_token"]
Ejemplo n.º 18
0
def get_shipping_costs(tree, free_shipping_string):
    # Assume Free Shipping and change otherwise

    # Shipping collection xpath:
    # .//div[starts-with(@id, 'aod-bottlingDepositFee-')]/following-sibling::span
    shipping_nodes = tree.xpath(
        ".//div[starts-with(@id, 'aod-bottlingDepositFee-')]/following-sibling::*[1]"
    )
    count = len(shipping_nodes)
    # log.debug(f"Found {count} shipping nodes.")
    if count == 0:
        log.warning("No shipping nodes found.  Assuming zero.")
        return FREE_SHIPPING_PRICE
    elif count > 1:
        log.warning("Found multiple shipping nodes.  Using the first.")

    shipping_node = shipping_nodes[0]
    # Shipping information is found within either a DIV or a SPAN following the bottleDepositFee DIV
    # What follows is logic to parse out the various pricing formats within the HTML.  Not ideal, but
    # it's what we have to work with.
    shipping_span_text = shipping_node.text.strip()
    if shipping_node.tag == "div":
        if shipping_span_text == "":
            # Assume zero shipping for an empty div
            log.debug(
                "Empty div found after bottleDepositFee.  Assuming zero shipping."
            )
            return FREE_SHIPPING_PRICE
        else:
            # Assume zero shipping for unknown values in
            log.warning(
                f"Non-Empty div found after bottleDepositFee.  Assuming zero. Stripped Value: '{shipping_span_text}'"
            )
            return FREE_SHIPPING_PRICE
    elif shipping_node.tag == "span":
        # Shipping values in the span are contained in:
        # - another SPAN
        # - hanging out alone in a B tag
        # - Hanging out alone in an I tag
        # - Nested in two I tags <i><i></i></i>
        # - "Prime FREE Delivery" in this node

        shipping_spans = shipping_node.findall("span")
        shipping_bs = shipping_node.findall("b")
        # shipping_is = shipping_node.findall("i")
        shipping_is = shipping_node.xpath("//i[@aria-label]")
        if len(shipping_spans) > 0:
            # If the span starts with a "& " it's free shipping (right?)
            if shipping_spans[0].text.strip() == "&":
                # & Free Shipping message
                # log.debug("Found '& Free', assuming zero.")
                return FREE_SHIPPING_PRICE
            elif shipping_spans[0].text.startswith("+"):
                return parse_price(shipping_spans[0].text.strip())
        elif len(shipping_bs) > 0:
            for message_node in shipping_bs:

                if message_node.text.upper() in free_shipping_string:
                    # log.debug("Found free shipping string.")
                    return FREE_SHIPPING_PRICE
                else:
                    log.error(
                        f"Couldn't parse price from <B>. Assuming 0. Do we need to add: '{message_node.text.upper()}'"
                    )
                    return FREE_SHIPPING_PRICE
        elif len(shipping_is) > 0:
            # If it has prime icon class, assume free Prime shipping
            if "FREE" in shipping_is[0].attrib["aria-label"].upper():
                # log.debug("Found Free shipping with Prime")
                return FREE_SHIPPING_PRICE
        elif any(shipping_span_text.upper() in free_message
                 for free_message in free_shipping_string):
            # We found some version of "free" inside the span.. but this relies on a match
            log.warning(
                f"Assuming free shipping based on this message: '{shipping_span_text}'"
            )
        else:
            log.error(
                f"Unable to locate price.  Assuming 0.  Found this: '{shipping_span_text}' "
                f"Consider reporting to #tech-support Discord.")
    return FREE_SHIPPING_PRICE
Ejemplo n.º 19
0
 def setWorkerStatus(self, status):
     log.debug('[setWorkerStatus] %s' % self.getDisplayName())
     self.status = status
     return True
Ejemplo n.º 20
0
 def access_token(self):
     if datetime.today().timestamp() >= self.token_data.get('expires_at'):
         log.debug('Access token expired')
         self.token_data = self.get_nvidia_access_token()
     return self.token_data['access_token']
Ejemplo n.º 21
0
 def play_agent(self, n_play):
     for _ in tqdm(range(n_play)):
         total_reward = self.play_episode()
         self.cacher.save_cacher("play_reward", total_reward)
         log.debug("Number of episode reward: {}".format(total_reward))
Ejemplo n.º 22
0
 def test_mock_zset(self):
     e = RedisExpSet(set_name='alice', level='fxh:')
     for i in range(1000, 0, -1):
         e.set_items({str(i)})
         log.debug('setItem' + str(i))
         time.sleep(0.5)
Ejemplo n.º 23
0
 def wait_for_pages(self, page_titles, t=30):
     log.debug(f"wait_for_pages({page_titles}, {t})")
     selenium_utils.wait_for_any_title(self.driver, page_titles, t)
Ejemplo n.º 24
0
 def setResult(self):
     log.debug('[setResult] %s' % self.getDisplayName())
     self.result = "Work finished, time for a beer ;-)"
     return True
Ejemplo n.º 25
0
import time, datetime

from utils.scheduler import unixtime_period
from utils.threading import run_threaded
from config import EXCHANGES, PERIOD
from cryptodata.save_ticker import save_ticker
from cryptodata.save_orderbook import save_orderbook
from cryptodata.save_trades import save_trades

import logging
from utils.logger import log
log.debug(f'Loading module {__name__}')
log.setLevel(logging.INFO)


def master_job(unixtime=None):
    """
    Kicks off all the data collection and writing to the database
    :return:
    """
    log.info(
        f'Started master job at time {time.ctime()} and unixtime {unixtime}')

    if not unixtime:
        unixtime = datetime.datetime.now().timestamp()

    jobs = [save_orderbook, save_trades, save_ticker]
    for job in jobs:
        for exch in EXCHANGES:
            for pair in exch['pairs']:
                run_threaded(
Ejemplo n.º 26
0
async def on_ready():
    print("Connected!\n")
    print("Logged in as:\n{}/{}#{}\n----------".format(bot.user.id,
                                                       bot.user.name,
                                                       bot.user.discriminator))
    print(
        "Bot version: {}\nAuthor(s): {}\nCode name: {}\nBuild date: {}".format(
            BUILD_VERSION, BUILD_AUTHORS, BUILD_CODENAME, BUILD_DATE))
    log.debug("Debugging enabled!")
    await set_default_status()
    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as e:
            log.error("Failed to load extension {}\n{}: {}".format(
                extension,
                type(e).__name__, e))
    if os.path.isdir("data/music"):
        try:
            bot.cogs["Music"].clear_cache()
            log.info("The music cache has been cleared!")
        except:
            log.warning("Failed to clear the music cache!")
    if config.enableMal:
        try:
            bot.load_extension("commands.myanimelist")
            log.info("The MyAnimeList module has been enabled!")
        except Exception as e:
            log.error("Failed to load the MyAnimeList module\n{}: {}".format(
                type(e).__name__, e))
    if config.enableOsu:
        log.info("The osu! module has been enabled in the config!")
    if config._dbots_token:
        log.info("Updating DBots Statistics...")
        r = requests.post("https://bots.discord.pw/api/bots/{}/stats".format(
            bot.user.id),
                          json={"server_count": len(bot.servers)},
                          headers={"Authorization": config._dbots_token})
        if r.status_code == "200":
            log.info("Discord Bots Server count updated.")
        elif r.status_code == "401":
            log.error(
                "An error occurred while trying to update the server count!")
    if config._carbonitex_key:
        log.info("Updating Carbonitex Statistics...")
        payload = {
            "key": config._carbonitex_key,
            "servercount": len(bot.servers),
            "botname": bot.user.name,
            "logoid": bot.user.avatar_url
        }
        owner = discord.utils.get(list(bot.get_all_members()),
                                  id=config.owner_id)
        if owner is not None:
            payload["ownername"] = owner.name
        r = requests.post(
            "https://www.carbonitex.net/discord/data/botdata.php",
            json=payload)
        if r.text == "1 - Success":
            log.info("Carbonitex stats updated")
        else:
            log.error(
                "Failed to update the carbonitex stats, double check the key in the config!"
            )
Ejemplo n.º 27
0
async def on_ready():
    print("Connected!\n")
    print("Logged in as:\n{}/{}#{}\n----------".format(bot.user.id, bot.user.name, bot.user.discriminator))
    print("Bot version: {}\nAuthor(s): {}\nCode name: {}\nBuild date: {}".format(BUILD_VERSION, BUILD_AUTHORS, BUILD_CODENAME, BUILD_DATE))
    log.debug("Debugging enabled!")
    if config.enable_default_status:
        await set_default_status()
    else:
        await bot.change_presence(activity=discord.Activity(name="Zwei", type=discord.ActivityType.watching), status=discord.Status.dnd)
    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as e:
            log.error("Failed to load extension {}\n{}: {}".format(extension, type(e).__name__, e))
    if os.path.isdir("data/music"):
        try:
            bot.cogs["Music"].clear_data()
            log.info("The music cache has been cleared!")
        except:
            log.warning("Failed to clear the music cache!")
    if config.enableMal:
        try:
            bot.load_extension("commands.myanimelist")
            log.info("The MyAnimeList module has been enabled!")
        except Exception as e:
            log.error("Failed to load the MyAnimeList module\n{}: {}".format(type(e).__name__, e))
    if config.enableOsu:
        log.info("The osu! module has been enabled in the config!")
    if config._dbots_token:
        log.info("Updating DBots Statistics...")
        try:
            r = requests.post("https://bots.discord.pw/api/bots/{}/stats".format(bot.user.id), json={
                "server_count": len(bot.guilds)}, headers={"Authorization": config._dbots_token}, timeout=5)
            if r.status_code == "200":
                log.info("Discord Bots guild count updated.")
            elif r.status_code == "401":
                log.error("An error occurred while trying to update the guild count!")
        except requests.exceptions.Timeout:
            log.error("Failed to update the guild count: request timed out.")
    if config._carbonitex_key:
        log.info("Updating Carbonitex Statistics...")
        payload = {"key": config._carbonitex_key, "guildcount": len(bot.guilds), "botname": bot.user.name,
                   "logoid": bot.user.avatar_url}
        owner = discord.utils.get(list(bot.get_all_members()), id=config.owner_id)
        if owner is not None:
            payload["ownername"] = owner.name
        try:
            r = requests.post("https://www.carbonitex.net/discord/data/botdata.php", json=payload, timeout=5)
            if r.text == "1 - Success":
                log.info("Carbonitex stats updated")
            else:
                log.error("Failed to update the carbonitex stats, double check the key in the config!")
        except requests.exceptions.Timeout:
            log.error("Failed to update the carbonitex stats: request timed out")

    if config.enableSteam:
        if not config._steamAPIKey:
            log.warning("The steam module was enabled but no steam web api key was specified, disabling...")
        else:
            bot.load_extension("commands.steam")
            log.info("The steam module has been enabled!")
Ejemplo n.º 28
0
def signal_handler(signal, frame):
    # ToDo: Clean everithing
    log.debug("Exiting...")
    exit(0)
Ejemplo n.º 29
0
 def get_cart(self, token):
     log.debug('StoreClient::get_cart(): %s' % token)
Ejemplo n.º 30
0
 async def makemeasandwich(self, ctx):
     if self.pissed:
         await self.bot.say("DON'T TELL ME WHAT TO DO!")
         return
     await self.bot.say("DON'T TELL ME WHAT TO DO!")
     state = self.get_voice_state(ctx.message.server)
     while state.is_playing():
         state.skip()
     #self.disconnect(self, ctx)
     #self.summon(self, ctx)
     for i in range(5):
         #self.play(self, ctx, "heyyeyaaeyaaaeyaeyaa")
         song = "heyyeyaaeyaaaeyaeyaa"
         song = song.strip("<>")
         try:
             state = self.get_voice_state(ctx.message.server)
             if state.voice is None:
                 success = await ctx.invoke(self.summon)
                 if not success:
                     return
             ytdl = get_ytdl(ctx.message.server.id)
             try:
                 song_info = ytdl.extract_info(song,
                                               download=False,
                                               process=False)
                 if "url" in song_info:
                     if song_info["url"].startswith("ytsearch"):
                         song_info = ytdl.extract_info(song_info["url"],
                                                       download=False,
                                                       process=False)
                         log.debug(song_info)
                     if "entries" in song_info:
                         url = song_info["entries"][0]["url"]
                     else:
                         url = song_info["url"]
                     url = "https://youtube.com/watch?v={}".format(url)
                 else:
                     url = song
                 log.debug(url)
                 song_info = ytdl.extract_info(url, download=True)
                 id = song_info["id"]
                 title = song_info["title"]
                 file_url = "data/music/{}/{}.mp3".format(
                     ctx.message.server.id, id)
                 await asyncio.sleep(2)
                 player = state.voice.create_ffmpeg_player(
                     file_url,
                     stderr=subprocess.PIPE,
                     after=state.toggle_next)
             except Exception as e:
                 await self.bot.say(
                     "An error occurred while processing this request: {}".
                     format(
                         py.format("{}: {}\n{}".format(
                             type(e).__name__, e, traceback.format_exc()))))
                 return
             player.volume = state.volume
             entry = VoiceEntry(ctx.message, player, song_info, file_url)
             await self.bot.say("Enqueued {}".format(entry))
             await state.songs.put(entry)
             state.queue.append(entry)
         except Exception as e:
             await self.bot.say(traceback.format_exc())
             log.debug("{}: {}\n\n{}".format(
                 type(e).__name__, e, traceback.format_exc()))
     self.pissed = True
Ejemplo n.º 31
0
 def wait_for_pages(self, page_titles, t=30):
     try:
         selenium_utils.wait_for_any_title(self.driver, page_titles, t)
     except Exception as e:
         log.debug(f"wait_for_pages exception: {e}")
         pass
Ejemplo n.º 32
0
    def check_stock(self, asin, reserve_min, reserve_max, retry=0):
        if retry > DEFAULT_MAX_ATC_TRIES:
            log.info("max add to cart retries hit, returning to asin check")
            return False
        if self.checkshipping:
            if self.used:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin)
            else:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin +
                         "/ref=olp_f_new&f_new=true")
        else:
            if self.used:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin +
                         "/f_freeShipping=on")
            else:
                f = furl(AMAZON_URLS["OFFER_URL"] + asin +
                         "/ref=olp_f_new&f_new=true&f_freeShipping=on")
        try:
            while True:
                try:
                    try:
                        searching_update()
                    except Exception:
                        pass
                    self.driver.get(f.url)
                    break
                except Exception:
                    log.error(
                        "Failed to get the URL, were in the exception now.")
                    time.sleep(3)
                    pass
            elements = self.driver.find_elements_by_xpath(
                '//*[@name="submit.addToCart"]')
            prices = self.driver.find_elements_by_xpath(
                '//*[@class="a-size-large a-color-price olpOfferPrice a-text-bold"]'
            )
            shipping = self.driver.find_elements_by_xpath(
                '//*[@class="a-color-secondary"]')
        except Exception as e:
            log.error(e)
            return None

        in_stock = False
        for i in range(len(elements)):
            price = parse_price(prices[i].text)
            if SHIPPING_ONLY_IF in shipping[i].text:
                ship_price = parse_price("0")
            else:
                ship_price = parse_price(shipping[i].text)
            ship_float = ship_price.amount
            price_float = price.amount
            if price_float is None:
                return False
            if ship_float is None or not self.checkshipping:
                ship_float = 0

            if ((ship_float + price_float) <= reserve_max or math.isclose(
                (price_float + ship_float), reserve_max, abs_tol=0.01)) and (
                    (ship_float + price_float) >= reserve_min or math.isclose(
                        (price_float + ship_float), reserve_min,
                        abs_tol=0.01)):
                log.info("Item in stock and in reserve range!")
                log.info("clicking add to cart")
                try:
                    buy_update()
                except:
                    pass
                elements[i].click()
                time.sleep(self.page_wait_delay())
                if self.driver.title in SHOPING_CART_TITLES:
                    return True
                else:
                    log.info("did not add to cart, trying again")
                    log.debug(f"failed title was {self.driver.title}")
                    if self.no_screenshots:
                        self.notification_handler.send_notification(
                            "failed-atc")
                    else:
                        self.save_screenshot("failed-atc")
                    self.save_page_source("failed-atc")
                    in_stock = self.check_stock(
                        asin=asin,
                        reserve_max=reserve_max,
                        reserve_min=reserve_min,
                        retry=retry + 1,
                    )
        return in_stock
Ejemplo n.º 33
0
    def buy(self, delay=5, test=False):
        if test:
            self.driver.get(
                "https://www.evga.com/products/ProductList.aspx?type=0&family=GeForce+16+Series+Family&chipset=GTX+1660")
            selenium_utils.wait_for_page(self.driver,
                                         "EVGA - Products - Graphics - GeForce 16 Series Family - GTX 1660")
        else:
            self.driver.get(
                "https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+3080"
            )
            selenium_utils.wait_for_page(
                self.driver,
                "EVGA - Products - Graphics - GeForce 30 Series Family - RTX 3080",
            )

        #  Check for stock
        log.info("On GPU Page")
        atc_buttons = self.driver.find_elements_by_xpath(
            '//input[@class="btnBigAddCart"]'
        )
        while not atc_buttons:
            log.debug("Refreshing page for GPU")
            self.driver.refresh()
            atc_buttons = self.driver.find_elements_by_xpath(
                '//input[@class="btnBigAddCart"]'
            )
            sleep(delay)

        #  Add to cart
        atc_buttons[0].click()

        #  Go to checkout
        selenium_utils.wait_for_page(self.driver, "EVGA - Checkout")
        selenium_utils.button_click_using_xpath(
            self.driver, '//*[@id="LFrame_CheckoutButton"]'
        )

        # Shipping Address screen
        selenium_utils.wait_for_page(self.driver, "Shopping")

        log.info("Skip that page.")
        self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx")

        selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Billing Options")

        log.info("Ensure that we are paying with credit card")
        sleep(1)  # Fix this.
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, './/input[@value="rdoCreditCard"]'))
        ).click()
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(
                (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]')
            )
        ).click()

        selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_txtNameOnCard")

        log.info("Populate credit card fields")

        selenium_utils.field_send_keys(
            self.driver, "ctl00$LFrame$txtNameOnCard", self.credit_card["name"]
        )
        selenium_utils.field_send_keys(
            self.driver, "ctl00$LFrame$txtCardNumber", self.credit_card["number"]
        )
        selenium_utils.field_send_keys(
            self.driver, "ctl00$LFrame$txtCvv", self.credit_card["cvv"]
        )
        Select(self.driver.find_element_by_id("ctl00_LFrame_ddlMonth")).select_by_value(
            self.credit_card["expiration_month"]
        )
        Select(self.driver.find_element_by_id("ctl00_LFrame_ddlYear")).select_by_value(
            self.credit_card["expiration_year"]
        )
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(
                (
                    By.XPATH,
                    "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]",
                )
            )
        ).click()

        log.info("Finalize Order Page")
        selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Finalize Order")

        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, "ctl00_LFrame_cbAgree"))
        ).click()

        selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_btncontinue")

        if not test:
            WebDriverWait(self.driver, 10).until(
                EC.element_to_be_clickable((By.ID, "ctl00_LFrame_btncontinue"))
            ).click()

        log.info("Finalized Order!")
Ejemplo n.º 34
0
    def login(self):
        log.info("Email")
        email_field = None
        password_field = None
        timeout = self.get_timeout()
        while True:
            try:
                email_field = self.driver.find_element_by_xpath('//*[@id="ap_email"]')
                break
            except exceptions.NoSuchElementException:
                try:
                    password_field = self.driver.find_element_by_xpath(
                        '//*[@id="ap_password"]'
                    )
                    break
                except exceptions.NoSuchElementException:
                    pass
            if time.time() > timeout:
                break

        if email_field:
            try:
                email_field.send_keys(self.username + Keys.RETURN)
            except exceptions.ElementNotInteractableException:
                log.info("Email not needed.")
        else:
            log.info("Email not needed.")

        if self.driver.find_elements_by_xpath('//*[@id="auth-error-message-box"]'):
            log.error("Login failed, delete your credentials file")
            time.sleep(240)
            exit(1)

        time.sleep(self.page_wait_delay())

        log.info("Remember me checkbox")
        try:
            self.driver.find_element_by_xpath('//*[@name="rememberMe"]').click()
        except exceptions.NoSuchElementException:
            log.error("Remember me checkbox did not exist")

        log.info("Password")
        password_field = None
        timeout = self.get_timeout()
        current_page = self.driver.title
        while True:
            try:
                password_field = self.driver.find_element_by_xpath(
                    '//*[@id="ap_password"]'
                )
                break
            except exceptions.NoSuchElementException:
                pass
            if time.time() > timeout:
                break
        if password_field:
            password_field.send_keys(self.password + Keys.RETURN)
            self.wait_for_page_change(current_page)
        else:
            log.error("Password entry box did not exist")

        # check for captcha
        try:
            if self.driver.find_element_by_xpath(
                '//form[@action="/errors/validateCaptcha"]'
            ):
                try:
                    log.info("Stuck on a captcha... Lets try to solve it.")
                    captcha = AmazonCaptcha.fromdriver(self.driver)
                    solution = captcha.solve()
                    log.info(f"The solution is: {solution}")
                    if solution == "Not solved":
                        log.info(
                            f"Failed to solve {captcha.image_link}, lets reload and get a new captcha."
                        )
                        self.driver.refresh()
                    else:
                        self.send_notification(
                            "Solving catpcha", "captcha", self.take_screenshots
                        )
                        self.driver.find_element_by_xpath(
                            '//*[@id="captchacharacters"]'
                        ).send_keys(solution + Keys.RETURN)
                except Exception as e:
                    log.debug(e)
                    log.info("Error trying to solve captcha. Refresh and retry.")
                    self.driver.refresh()
        except exceptions.NoSuchElementException:
            log.debug("login page did not have captcha element")

        # time.sleep(self.page_wait_delay())
        if self.driver.title in TWOFA_TITLES:
            log.info("enter in your two-step verification code in browser")
            while self.driver.title in TWOFA_TITLES:
                time.sleep(0.2)
        log.info(f"Logged in as {self.username}")
Ejemplo n.º 35
0
    def selenium_checkout(self):
        log.info("Checking out.")
        autobuy_btns = autobuy_locale_btns[self.locale]
        params = {"token": self.access_token}
        url = furl(DIGITAL_RIVER_CHECKOUT_URL).set(params)
        self.driver.get(url.url)
        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['checkout']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["checkout"])

        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()
        log.debug(f"Entering security code to 'cardSecurityCode'")
        security_code = selenium_utils.wait_for_element(
            self.driver, "cardSecurityCode")
        security_code.send_keys(self.cvv)
        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()

        try:
            log.debug(
                f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
            )
            selenium_utils.wait_for_page(
                self.driver,
                PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        except TimeoutException:
            log.debug("Address validation required?")
            self.address_validation_page()

        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        log.info("Submit.")
        log.debug("Reached order validation page.")
        self.driver.save_screenshot("nvidia-order-validation.png")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[1]}"]').click()
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["order_completed"],
            5)
        self.driver.save_screenshot("nvidia-order-finshed.png")
        log.info("Done.")
Ejemplo n.º 36
0
    def buy(self, delay=5, test=False):
        if test:
            log.info("Refreshing Page Until Title Matches ...")
            selenium_utils.wait_for_title(
                self.driver,
                "EVGA - Products - Graphics - GeForce 16 Series Family - GTX 1660",
                "https://www.evga.com/products/ProductList.aspx?type=0&family=GeForce+16+Series+Family&chipset=GTX+1660",
            )
        else:
            log.info("Refreshing Page Until Title Matches ...")
            selenium_utils.wait_for_title(
                self.driver,
                "EVGA - Products - Graphics - GeForce 30 Series Family - RTX "
                + self.card_series,
                "https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+"
                + self.card_series,
            )

        log.info("matched chipset=RTX+" + self.card_series + "!")

        if self.card_pn and not test:
            # check for card
            log.info("On GPU list Page")
            card_btn = self.driver.find_elements_by_xpath(
                "//a[@href='/products/product.aspx?pn=" + self.card_pn + "']")
            while not card_btn:
                log.debug("Refreshing page for GPU")
                self.driver.refresh()
                card_btn = self.driver.find_elements_by_xpath(
                    "//a[@href='/products/product.aspx?pn=" + self.card_pn +
                    "']")
                sleep(delay)

            card_btn[0].click()

        #  Check for stock
        log.info("On GPU Page")
        atc_buttons = self.driver.find_elements_by_xpath(
            '//input[@class="btnBigAddCart"]')
        while not atc_buttons:
            log.debug("Refreshing page for GPU")
            self.driver.refresh()
            atc_buttons = self.driver.find_elements_by_xpath(
                '//input[@class="btnBigAddCart"]')
            sleep(delay)

        #  Add to cart
        atc_buttons[0].click()

        # Send notification that product is available
        self.notification_handler.send_notification(
            f"📦 Card found in stock at EVGA (P/N {self.card_pn})…")

        #  Go to checkout
        selenium_utils.wait_for_page(self.driver, "EVGA - Checkout")
        selenium_utils.button_click_using_xpath(
            self.driver, '//*[@id="LFrame_CheckoutButton"]')

        # Shipping Address screen
        selenium_utils.wait_for_page(self.driver, "Shopping")

        log.info("Skip that page.")
        self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx")

        selenium_utils.wait_for_page(self.driver,
                                     "EVGA - Checkout - Billing Options")

        log.info("Ensure that we are paying with credit card")
        sleep(3)
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(
                (By.XPATH, './/input[@value="rdoCreditCard"]'))).click()
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(
                (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]'))).click()

        selenium_utils.wait_for_element(self.driver,
                                        "ctl00_LFrame_txtNameOnCard")

        log.info("Populate credit card fields")

        selenium_utils.field_send_keys(self.driver,
                                       "ctl00$LFrame$txtNameOnCard",
                                       self.credit_card["name"])
        selenium_utils.field_send_keys(self.driver,
                                       "ctl00$LFrame$txtCardNumber",
                                       self.credit_card["number"])
        selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCvv",
                                       self.credit_card["cvv"])
        Select(self.driver.find_element_by_id(
            "ctl00_LFrame_ddlMonth")).select_by_value(
                self.credit_card["expiration_month"])
        Select(self.driver.find_element_by_id(
            "ctl00_LFrame_ddlYear")).select_by_value(
                self.credit_card["expiration_year"])
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((
                By.XPATH,
                "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]",
            ))).click()

        try:
            WebDriverWait(self.driver, 10).until(
                EC.element_to_be_clickable((
                    By.XPATH,
                    "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]",
                ))).click()
        except:
            pass

        log.info("Finalize Order Page")
        selenium_utils.wait_for_page(self.driver,
                                     "EVGA - Checkout - Finalize Order")

        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(
                (By.ID, "ctl00_LFrame_cbAgree"))).click()

        if not test:
            WebDriverWait(self.driver, 10).until(
                EC.element_to_be_clickable(
                    (By.ID, "ctl00_LFrame_btncontinue"))).click()

        log.info("Finalized Order!")

        # Send extra notification alerting user that we've successfully ordered.
        self.notification_handler.send_notification(
            f"🎉 Order submitted at EVGA for {self.card_pn}",
            audio_file="purchase.mp3",
        )
Ejemplo n.º 37
0
 async def disconnect_all_voice_clients(self):
     for id in self.voice_states:
         state = self.voice_states[id]
         state.audio_player.cancel()
         await state.voice.disconnect()
     log.debug("All voice clients were disconnected!")
Ejemplo n.º 38
0
                  workers[name]['instance'].getResult()))
    return True


if __name__ == "__main__":
    with open(CFG_FILE) as c:
        config = json.load(c)
        scheduler = Scheduler()
        scheduler.start()
        signal.signal(signal.SIGINT, signal_handler)
        print(
            text2art('-----------------------\n    Welcome   to   ' +
                     config['general']['name'] + "   " +
                     config['general']['version'] +
                     '\n-----------------------'))
        log.debug("Starting %s v%s" %
                  (config['general']['name'], config['general']['version']))
        # Main loop waiting & polling
        workers = {}
        for worker in config['workers']:
            workers[worker] = {
                'import': None,
                'config': None,
                'instance': None
            }
            workers[worker]['config'] = config['workers'][worker]
            log.info("Loading worker module: %s", worker)
            log.debug("Loading worker %s config. from properties file: %s" %
                      (worker, workers[worker]['config']))
            workers[worker]['import'] = __import__('modules.workers.' + worker,
                                                   fromlist=[worker])
            workers[worker]['instance'] = workers[worker]['import'].Worker(