Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from lxml.html import tostring, html5parser
- namespaces = {'html': 'http://www.w3.org/1999/xhtml'}
- def parsetable(url, path='//html:table'):
- html = html5parser.parse(url)
- table = html.find(path, namespaces=namespaces)
- headers = [header.text for header in table.findall('html:thead/html:tr/html:th', namespaces=namespaces)]
- rows = table.findall('html:tbody/html:tr', namespaces=namespaces)
- return [dict(zip(headers, [tostring(col, encoding=str, method='text') for col in row])) for row in iter(rows)]
- def tagfilter(tags, gender, role, blacklist = []):
- tags = iter(tags)
- tag, thresh = next(tags)
- table = parsetable('http://rp.aryion.com/characters.php?term={}'.format(tag))
- for row in table:
- if row['Character'] in blacklist:
- continue
- if gender != row['Gender'] or int(row[role]) < thresh:
- blacklist.append(row['Character'])
- try:
- return tagfilter(tags, gender, role, blacklist)
- except StopIteration:
- return [row['Character'] for row in table if row['Character'] not in blacklist]
- from sys import argv
- args = argv
- argv.pop(0)
- gender = { 'female': 'F',
- 'f': 'F',
- 'fem': 'F',
- 'male': 'M',
- 'm': 'M',
- 'herm': 'H',
- 'h': 'H',
- 'undefined': 'U',
- 'u': 'U' }[argv.pop(0)]
- role = { 'prey': 'For prey',
- 'pred': 'For pred' }[argv.pop(0)]
- tags = []
- while len(argv) > 1:
- tag = argv.pop(0)
- thresh = int(argv.pop(0))
- tags.append((tag, thresh))
- print(tags)
- for i in tagfilter(tags, gender, role):
- print('https://profile.aryion.com/profile/{}'.format(i))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement