-
Notifications
You must be signed in to change notification settings - Fork 2
/
wwstats.py
47 lines (38 loc) · 1.27 KB
/
wwstats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
# -*- coding: utf-8 -*
from bs4 import BeautifulSoup
from bs4 import UnicodeDammit
import requests
import urllib.request
import urllib.parse
import codecs
from config import *
def check(id):
url = "http://tgwerewolf.com/stats/PlayerAchievements/?pid=" + str(id)
stats = {}
#url = urllib.parse.quote(url)
# r = requests.get(url)
# soup = BeautifulSoup(r.content)
# soup = str(r.content)
# output = soup.prettify("utf-8")
# output = soup.encode("utf-8")
# output = UnicodeDammit(soup)
# output = codecs.decode(soup, 'unicode_escape').encode('latin1').decode('utf8')
# print(output)
r = requests.get(url)
dump = BeautifulSoup(r.json(), 'html.parser')
db = dump('td')
num = 0
for i in range(0, len(db), 2):
stats[num] = db[i].string
num = num + 1
msg = "ATTAINED ({0}/{1}):\n".format(str(len(stats)), str(len(ACHV)))
for x in stats:
if stats[x] in [y['name'] for y in ACHV]:
msg += "- `" + stats[x] + "`\n"
msg2 = "\nMISSING ({0}/{1}):\n".format(str(len(ACHV)-len(stats)), str(len(ACHV)))
for z in ACHV:
if z['name'] not in stats.values():
msg2 += "- `" + z['name'] + "`\n"
msg2 += ">>> _" + z['desc'] + "_\n"
return msg, msg2