"""List upcoming CTFs"""

# PYTHON STUFFS #######################################################

from bs4 import BeautifulSoup

from nemubot.hooks import hook
from nemubot.tools.web import getURLContent, striphtml
from nemubot.module.more import Response


# GLOBALS #############################################################

URL = 'https://ctftime.org/event/list/upcoming'


# MODULE INTERFACE ####################################################

@hook.command("ctfs",
      help="Display the upcoming CTFs")
def get_info_yt(msg):
    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) == 5:
            try:
                res.append_message("\x02%s:\x0F from %s type %s at %s. %s" %
                                   tuple([striphtml(x.text) for x in n]))
            except:
                pass
    return res

@@ -749,32 +749,11 @@
  == 
-5
+7
 :%0A
-            try:%0A    
     
@@ -819,18 +819,28 @@
 %25s. 
+Weight: %25s. %25s
 %25s%22 %25%0A
-    
     
@@ -890,16 +890,24 @@
 (x.text)
+.strip()
  for x i
@@ -917,48 +917,8 @@
 %5D))%0A
-            except:%0A                pass
 %0A   

update module reflecting site changes