-
-
Save majkrzak/088f2276cec06e25763c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from lxml import etree | |
from urllib.request import urlopen | |
from re import search | |
import json | |
def polls(): | |
for pool in json.loads(str(urlopen('''http://aao25.com/stats/pollview.php''').read(),'ascii')): | |
print('%d: %s'%(int(pool['id']),pool['question'])) | |
for i,option in zip(range(len(pool['options'])),pool['options']): | |
print('\t%d: %s(%d)'%(i,option['option'],int(option['votes']))) | |
def vote(pool,v): | |
for player in [ int(search('''/([0-9]+)/''',str(url)).group(1)) for server in [str(text) for text in etree.HTML(urlopen('''https://battletracker.com/index.php?page=AAOServerlist''').read()).xpath('''//tr[contains(@id,'server') and not(substring(td[6]//text(),0,2)='0')]/td[2]/p/text()''')] for url in etree.HTML(urlopen('''https://battletracker.com/aaoserver/%s/'''%server).read()).xpath('''//a[contains(@href,'playerstats/aao')]/@href''')]: | |
print('''http://aao25.com/stats/pollview.php?v=%d&btid=%d&poll=%d'''%(v,player,pool)) | |
res = str(urlopen('''http://aao25.com/stats/pollview.php?v=%d&btid=%d&poll=%d'''%(v,player,pool)).read()) | |
print(pool,v,player,res) | |
if __name__ == '__main__': | |
from sys import argv | |
if len(argv) == 2 and argv[1] == 'polls': | |
polls() | |
if len(argv) == 4 and argv[1] == 'vote': | |
vote(int(argv[2]),int(argv[3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment