Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
add new checkPrice command
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwenillia committed Jun 6, 2021
1 parent 6e6549c commit 9dbdfb3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ opencv-python-headless==4.5.2.52
opencv-python~=4.5.2.52
python-dateutil~=2.8.1
setuptools~=56.0.0
wavelink~=0.9.9
wavelink~=0.9.9
selenium~=3.141.0
51 changes: 51 additions & 0 deletions src/cogs/check_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import uuid

import discord
from defs import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class CheckPrice(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command(name="checkPrice", usage="checkPrice <nom d'un jeux>",
help="Donne une liste pour trouver un jeux au prix les plus bas")
async def check_price(self, ctx, *args):
if args is None:
await ctx.author.send('Tu dois préciser le nom d\'un jeux')
return

async with ctx.typing():
uid = uuid.uuid1()
FIREFOX_HEADER_OPTIONS.headless = True
driver = webdriver.Firefox(options=FIREFOX_HEADER_OPTIONS)
wait = WebDriverWait(driver, 30)
scrapped_link = f"https://www.goclecd.fr/catalogue/category-pc-games-all/search-{'+'.join(args)}/sort-relevance-asc/"
driver.get(scrapped_link)
wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR,
'div.aks-lazyloaded'))).get_attribute(
"style")
list = driver.find_element_by_class_name('search-results')
try:
with open(f"temp_list_image-{uid}.png", "wb") as temp_list_img:
temp_list_img.write(list.screenshot_as_png)
except Exception:
print('Can\'t save image')

e = discord.Embed(title="Voici ce que j'ai trouvé !", url=scrapped_link, color=DEFAULT_COLOR)
file = discord.File(temp_list_img.name, filename=temp_list_img.name)
e.set_image(url="attachment://" + temp_list_img.name)
await ctx.send(file=file, embed=e)
os.remove(temp_list_img.name)

driver.close()


def setup(bot):
bot.add_cog(CheckPrice(bot))
3 changes: 3 additions & 0 deletions src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytz
from discord.ext import commands
from dotenv import load_dotenv
from selenium.webdriver.firefox.options import Options

load_dotenv()

Expand All @@ -14,6 +15,7 @@
'cogs.flux.del_rss',
'cogs.flux.flux',
'cogs.flux.reload',
'cogs.check_price'
]

CSV_PARAM = "./param.csv"
Expand All @@ -23,6 +25,7 @@
PREFIX = os.getenv("PREFIX")
bot = commands.Bot(command_prefix=PREFIX, help_command=None)
DEFAULT_COLOR = 0x2b41ff
FIREFOX_HEADER_OPTIONS = Options()
PARAM_CSV = []
FIELD_NAMES = []
TZINFOS = {
Expand Down

0 comments on commit 9dbdfb3

Please sign in to comment.