mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 13:02:38 +00:00
Add personal temp notifications
This commit is contained in:
parent
f2f7ee4eae
commit
3df2438c79
3 changed files with 65 additions and 2 deletions
1
Pipfile
1
Pipfile
|
@ -22,6 +22,7 @@ beautifulsoup4 = "*"
|
|||
requests = "*"
|
||||
html5lib = "*"
|
||||
tldextract = "*"
|
||||
selenium = "*"
|
||||
|
||||
[dev-packages]
|
||||
lxml = "*"
|
||||
|
|
61
src/cogs/weeb.py
Normal file
61
src/cogs/weeb.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
from selenium.webdriver import Chrome
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
|
||||
import asyncio
|
||||
import traceback as tb
|
||||
from discord.ext import commands as cmds
|
||||
from utils import utils as u
|
||||
|
||||
|
||||
class Weeb(cmds.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.weebing = False
|
||||
|
||||
with open('id.json') as f:
|
||||
self.id = int(f.readline())
|
||||
print('LOADED : id.json')
|
||||
|
||||
if not self.weebing:
|
||||
self.weebing = True
|
||||
self.bot.loop.create_task(self.start())
|
||||
print('STARTED : weebing')
|
||||
|
||||
async def refresh(self, browser, urls):
|
||||
message = ''
|
||||
|
||||
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'
|
||||
|
||||
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)
|
||||
|
||||
if message:
|
||||
await self.bot.get_user(self.id).send(message)
|
||||
await self.bot.get_user(u.config['owner_id']).send('Message sent')
|
||||
|
||||
browser.quit()
|
||||
self.weebing = False
|
||||
|
||||
await asyncio.sleep(60)
|
||||
|
||||
except Exception as e:
|
||||
tb.print_exc()
|
||||
await self.bot.get_user(u.config['owner_id']).send(f'! ERROR !\n\n{repr(e)}')
|
|
@ -32,14 +32,15 @@ bot = cmds.Bot(
|
|||
@bot.event
|
||||
async def on_ready():
|
||||
if not checks.ready:
|
||||
from cogs import booru, info, management, owner, tools
|
||||
from cogs import weeb, booru, info, management, owner, tools
|
||||
|
||||
for cog in (
|
||||
tools.Utils(bot),
|
||||
owner.Bot(bot),
|
||||
management.Admin(bot),
|
||||
info.Info(bot),
|
||||
booru.MsG(bot)):
|
||||
booru.MsG(bot),
|
||||
weeb.Weeb(bot)):
|
||||
bot.add_cog(cog)
|
||||
u.cogs[type(cog).__name__] = cog
|
||||
print(f'COG : {type(cog).__name__}')
|
||||
|
|
Loading…
Reference in a new issue