added delay for running commands in rcon channel, updated scraping to be even more generic.

This commit is contained in:
jenz 2022-06-25 13:40:30 +02:00
parent 0c45287ae6
commit e2795c8edc
2 changed files with 50 additions and 39 deletions

View File

@ -3,6 +3,7 @@
import discord
from datetime import datetime
from discord.ext.tasks import loop
from time import sleep
from settings import get_connection_event, token
intents = discord.Intents.default()
@ -77,6 +78,8 @@ async def discord_task():
#silly white space none sense
if len(map) > 3:
cooldown_msg = f"""sm_nominate_exclude_time {map} 1 0"""
#adding slight delay
sleep(1)
await r.send(cooldown_msg)
conn.commit()

View File

@ -50,47 +50,55 @@ class unloze_spider(scrapy.Spider):
try:
event_title = response.url.rsplit(".", 1)[0].rsplit("/", 1)[1]
event_server = ""
#several event managers do the threads differently in terms of highlighting and marks, they dont use standardization
index = 0
for r in response.xpath("//span[contains(text(),'TL;DR')]/../../../text()").extract():
if "\n" in r or len(r) < 4:
continue
if index < 2:
event_server += r
if index == 2:
event_date = r
if index == 3:
event_time = r
#just skipping the leader part on ze
if index == 4 and '27015' not in event_server:
event_reward = r
if index == 5 and '27015' in event_server:
event_reward = r
index += 1
event_maps = ""
for r in response.xpath("//span[contains(text(),'TL;DR')]/../../../a/text()").extract():
event_maps += f"{r} "
if not index:
tldr_count = 0
for r in response.xpath("//b[contains(text(),'TL;DR')]/../../../span//text()").extract():
if "\n" in r or len(r) < 4:
continue
if "TL;DR" in r:
tldr_count += 1
if tldr_count < 2:
continue
if index == 2 or index == 4:
event_server += r
if index == 7:
event_date = r
if index == 9:
event_time = r
if index == 13:
event_reward = r
index += 1
for r in response.xpath("//b[contains(text(),'TL;DR')]/../../../a//text()").extract():
#several event managers do the threads differently in terms of highlighting and marks, they dont use or understand standardization welp
#as long as no random nigger types TL;DR in their post i guess this will work
skipping = len(response.xpath("//*[contains(text(),'TL;DR')]").extract())
next_event_maps = False
next_event_date = False
next_event_server = False
next_event_time = False
next_event_reward = False
for r in response.xpath("//*[contains(text(),'TL;DR')]/../../..//text()").extract():
if "\n" in r or len(r) < 4 or "\t" in r or skipping > 0:
if r.lower() == "tl;dr":
skipping -= 1
continue
if "server" in r.lower() and "time" not in r.lower():
next_event_server = True
continue
if next_event_server:
event_server += r
next_event_server = False
if "maps" in r.lower() and "rewards" not in r.lower():
next_event_maps = True
continue
if "date" in r.lower():
next_event_maps = False
next_event_date = True
continue
if next_event_maps:
event_maps += f"{r} "
if next_event_date:
next_event_date= False
event_date = r
if "time" in r.lower() and "server" not in r.lower():
next_event_time = True
continue
if next_event_time:
event_time = r
next_event_time = False
if "rewards" in r.lower():
next_event_reward = True
continue
if next_event_reward:
event_reward = r
next_event_reward = False
self.item["event_title"] = event_title
self.item["event_date"] = event_date
@ -108,4 +116,4 @@ class unloze_spider(scrapy.Spider):
sys.exit(1)
#pprint(self.item)
return self.item
return self.item