From 84d1e0d8787bc9b59d50f67e96845f62bdbbee23 Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 14 Oct 2020 19:48:23 -0400 Subject: [PATCH] Add additional website to notify --- src/cogs/weeb.py | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/cogs/weeb.py b/src/cogs/weeb.py index f5910d7..50b46f2 100644 --- a/src/cogs/weeb.py +++ b/src/cogs/weeb.py @@ -22,34 +22,53 @@ class Weeb(cmds.Cog): self.bot.loop.create_task(self.start()) print('STARTED : weebing') - async def refresh(self, browser, urls): - message = '' + async def refresh_switchmod(self, browser): + message = '' + urls = { + 'Novelties': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816880208', + 'Royal': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816945744' + } - for item, url in urls.items(): - browser.get(url) - status = browser.find_elements_by_css_selector('#addToCartText-product-template')[0].text + for item, url in urls.items(): + browser.get(url) + status = browser.find_elements_by_css_selector('#addToCartText-product-template')[0].text - if status != 'SOLD OUT': - message += f'{item} is in stock!\n{url}\n' + if status != 'SOLD OUT': + message += f'{item} is in stock at Switchmod!\n<{url}>\n' - return message + await asyncio.sleep(5) + + return message + + async def refresh_deskhero(self, browser): + message = '' + url = 'https://www.deskhero.ca/products/gmk-metaverse-2' + + browser.get(url) + royal_soldout = browser.find_elements_by_css_selector('#data-product-option-1-1')[0].get_attribute('data-soldout') + novelties_soldout = browser.find_elements_by_css_selector('#data-product-option-1-3')[0].get_attribute('data-soldout') + + if royal_soldout != 'true': + message += f'Royal is in stock at Deskhero!\n<{url}>\n' + if novelties_soldout != 'true': + message += f'Novelties is in stock at Deskhero!\n<{url}>\n' + + return message async def start(self): try: opts = Options() opts.headless = True browser = Chrome(executable_path='/usr/bin/chromedriver', options=opts) - urls = { - 'Novelties': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816880208', - 'Royal': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816945744' - } while self.weebing: - message = await self.refresh(browser, urls) + message = await self.refresh_switchmod(browser) + await asyncio.sleep(5) + message += await self.refresh_deskhero(browser) if message: await self.bot.get_user(self.id).send(message) - await self.bot.get_user(u.config['owner_id']).send('Message sent') + await self.bot.get_user(u.config['owner_id']).send('Something is in stock. Restart to keep checking') browser.quit() self.weebing = False