Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Probably not the best quality code
- # but it's fun, so who cares :)
- # Written by Tiin57
- # Don't remove that, okay thanks
- import requests, re
- from lxml import html
- from random import randint
- template = '''
- <center>
- <span id="%s" class="%s" style="%s font-size: 96px;">%s<br></span><br>
- <span style="font-size: 36px;">is a numpty</span>
- </center>\n
- '''
- whitelist = ('Tiin57', 'clolin01', 'Trex')
- def ternary(cond, iftrue, iffalse):
- if (cond):
- return iftrue
- else:
- return iffalse
- def check_text(ele):
- if ele.text != None:
- scheck = ele.getparent().get('style')
- return [ele.text, ternary(scheck, scheck, ele.get('style')), ele.getparent().getparent().tag == 'strong']
- if len(ele.getchildren()) != 0:
- return check_text(ele.getchildren()[0])
- def get_numpty(numpties):
- n = numpties[randint(0, len(numpties) - 1)]
- if n[0] in whitelist:
- return get_numpty(numpties)
- return n
- def index(req):
- findnumpty(req)
- def findnumpty(req):
- req.content_type = 'text/html'
- req.write('''
- <style>
- body {
- font-family: Tahoma, Geneva, Sans-Serif;
- font-size: 13px;
- }
- .bold {
- font-weight: bold
- }
- </style>
- ''')
- tree = html.fromstring(requests.get('http://forums.hexteria.com/showteam.php').text)
- elements = []
- numpties = []
- for i in tree.cssselect('td[width="60%"]'):
- elements.append(i)
- for i in elements:
- x = check_text(i)
- if x == None:
- continue
- text = x[0]
- style = x[1]
- isstrong = x[2]
- if text == '' or text.startswith(' start: ') or re.match(r'/[\s]+/', text):
- continue
- numpties.append(x)
- winner = get_numpty(numpties)
- req.write('<title>%s is a numpty</title>' % winner[0])
- req.write(template % (winner[0], ternary(winner[2], 'bold', ''), winner[1], winner[0]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement