[ctfs] Improve module

This commit is contained in:
nemunaire 2015-06-08 14:57:21 +02:00
parent 381cf13432
commit 859b32abb7

View File

@ -1,37 +1,25 @@
import urllib.request
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from hooks import hook
from nemubot.hooks import hook
from nemubot.tools.web import getURLContent
from more import Response from more import Response
nemubotversion = 3.4 """List upcoming CTFs"""
def help_tiny(): nemubotversion = 4.0
return "No help"
def help_full():
return "No help "
@hook("cmd_hook", "ctfs") @hook("cmd_hook", "ctfs")
def get_info_yt(msg): def get_info_yt(msg):
req = urllib.request.Request('https://ctftime.org/event/list/upcoming', soup = BeautifulSoup(getURLContent('https://ctftime.org/event/list/upcoming'))
data=None, res = Response(channel=msg.channel, nomore="No more upcoming CTF")
headers={ for line in soup.body.find_all('tr'):
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' n = line.find_all('td')
}) if len(n) == 5:
try:
ctf = '' res.append_message("\x02%s:\x0F from %s type %s at %s. %s" % tuple([x.text.replace("\n", " ").strip() for x in n]))
url = urllib.request.urlopen(req) except:
soup = BeautifulSoup(url) import sys
desc = soup.body.find_all('td') import traceback
i = 0 exc_type, exc_value, _ = sys.exc_info()
for result in desc: sys.stderr.write(traceback.format_exception_only(exc_type, exc_value)[0])
ctf += result.text.replace('\n', ' ')
ctf += ' '
i += 1
if not (i % 5):
ctf += '\n'
res = Response(channel=msg.channel, nomore="No more description")
res.append_message(ctf)
return res return res