feat: Add Russian Roulette feature betwwen two players
Some checks failed
CD / Deploy to VPS (push) Has been cancelled
Some checks failed
CD / Deploy to VPS (push) Has been cancelled
This commit is contained in:
34
cogs/cs.py
34
cogs/cs.py
@@ -1,15 +1,18 @@
|
||||
import discord, datetime, os, re, json
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.firefox.options import Options
|
||||
from selenium.webdriver.firefox.service import Service
|
||||
from bs4 import BeautifulSoup
|
||||
from discord.ext import commands, tasks, bridge
|
||||
from setup.logger import LOGGER
|
||||
from setup.config import Config
|
||||
from models.cs_models import *
|
||||
|
||||
BASE_URL = "https://www.hltv.org"
|
||||
|
||||
PAGE_FILE = os.path.join("data","hltv.html")
|
||||
PAGE_FILE = os.path.join(Config.CONFIG_PATH,"hltv.html")
|
||||
|
||||
MATCHES_FILE = os.path.join("data","matches.json")
|
||||
MATCHES_FILE = os.path.join(Config.CONFIG_PATH,"matches.json")
|
||||
|
||||
# Cache duration in seconds (6 hours)
|
||||
DATA_CACHE_DURATION = 3600 * 6
|
||||
@@ -43,14 +46,27 @@ class CSCog(commands.Cog):
|
||||
return False
|
||||
|
||||
def get_page(self) -> None:
|
||||
"""Get the page from https://www.hltv.org/matches/ using Firefox webdriver and save to PAGE_FILE."""
|
||||
driver = webdriver.Firefox()
|
||||
driver.get("https://www.hltv.org/matches/")
|
||||
html = driver.page_source
|
||||
driver.close()
|
||||
"""Get the page from https://www.hltv.org/matches/ using a headless Firefox webdriver and save to PAGE_FILE."""
|
||||
options = Options()
|
||||
options.add_argument("--headless=new")
|
||||
options.add_argument("--no-sandbox")
|
||||
options.add_argument("--disable-dev-shm-usage")
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
|
||||
with open(PAGE_FILE, 'w') as f:
|
||||
f.write(html)
|
||||
geckodriver_path = os.getenv("GECKODRIVER_PATH")
|
||||
service = Service(executable_path=geckodriver_path) if geckodriver_path else None
|
||||
|
||||
driver = None
|
||||
try:
|
||||
driver = webdriver.Firefox(service=service, options=options)
|
||||
driver.get("https://www.hltv.org/matches/")
|
||||
html = driver.page_source
|
||||
|
||||
with open(PAGE_FILE, 'w', encoding='utf-8') as f:
|
||||
f.write(html)
|
||||
finally:
|
||||
if driver is not None:
|
||||
driver.quit()
|
||||
|
||||
def save(self) -> None:
|
||||
"""Save self.matches to MATCHES_FILE."""
|
||||
|
||||
Reference in New Issue
Block a user