nemubot/modules/ctfs.py

33 lines
936 B
Python
Raw Normal View History

2015-10-05 21:54:38 +00:00
"""List upcoming CTFs"""
# PYTHON STUFFS #######################################################
2015-06-08 07:46:01 +00:00
from bs4 import BeautifulSoup
2015-06-08 12:57:21 +00:00
from nemubot.hooks import hook
2015-10-05 21:54:38 +00:00
from nemubot.tools.web import getURLContent, striphtml
from nemubot.module.more import Response
2015-06-08 07:46:01 +00:00
2015-10-05 21:54:38 +00:00
# GLOBALS #############################################################
URL = 'https://ctftime.org/event/list/upcoming'
2015-06-08 07:46:01 +00:00
2015-10-05 21:54:38 +00:00
# MODULE INTERFACE ####################################################
2015-11-02 19:19:12 +00:00
@hook.command("ctfs",
2015-10-05 21:54:38 +00:00
help="Display the upcoming CTFs")
2015-06-08 07:46:01 +00:00
def get_info_yt(msg):
2015-10-05 21:54:38 +00:00
soup = BeautifulSoup(getURLContent(URL))
res = Response(channel=msg.channel, nomore="No more upcoming CTF")
for line in soup.body.find_all('tr'):
n = line.find_all('td')
if len(n) == 7:
res.append_message("\x02%s:\x0F from %s type %s at %s. Weight: %s. %s%s" %
tuple([striphtml(x.text).strip() for x in n]))
2015-10-05 21:54:38 +00:00
return res