-
Notifications
You must be signed in to change notification settings - Fork 15
/
edgebeeguildfinder.py
executable file
·83 lines (74 loc) · 2.78 KB
/
edgebeeguildfinder.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
# Edgebee guild finder -- given a list of user names,
# work out what edgebee guild those users come from. Output is csv,
# containing User, Game, and Guild
# also found at http://pastebin.com/W6sYanuQ
# Author: David Eccles (gringer) <coding@gringer.org>
# usage: echo -e "user1\nuser2" | ./edgebeeguildfinder.py
import cookielib, urllib2
import fileinput
import re
import sys
import json
import csv
userNames = []
addedUsers = set()
for line in fileinput.input():
if(line.startswith("{")):
jsonObj = json.loads(line)
if(('result' in jsonObj) and ('players' in jsonObj['result'])):
for userName in map(lambda x: x['name'],jsonObj['result']['players']):
if(not userName in addedUsers):
userNames.append(userName)
addedUsers.add(userName)
else:
userName = line.rstrip()
if(not userName in addedUsers):
userNames.append(userName)
addedUsers.add(userName)
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
f = opener.open('http://www.edgebee.com/signin?' +
'username=gringerscripts&password=gringerscripts&remember=1')
cr = csv.writer(sys.stdout)
cr.writerow(['User','Game','Guild','LastOnline','Registered'])
for user in userNames:
foundSandP = False
try:
f = opener.open('http://www.edgebee.com/user?name=%s' % (user))
except:
continue
inItem = False
gameName = None
extraStat = None
extraStats = {}
extraStats['lastOn'] = None
extraStats['regOn'] = None
extraStats['guildName'] = None
for line in f.read().splitlines(True):
line = line.rstrip()
if('playerListItem' in line):
inItem = True
gameName = None
extraStats['guildName'] = None
if(inItem):
if('h2' in line):
gameName = re.compile(r'<[^>]+>').sub('', line).lstrip()
if('h4' in line):
inItem = False
elif('h4' in line):
if('Registered on' in line):
extraStat = 'regOn'
elif('Last online' in line):
extraStat = 'lastOn'
else:
extraStat = None
elif((extraStat is not None) and ('<br>' in line)):
extraStats[extraStat] = re.compile(r'<[^>]+>').sub('', line).lstrip()
elif('Guild:' in line):
guildName = re.compile(r'<[^>]+>').sub('', line).lstrip()
guildName = guildName.replace('Guild: ','')
extraStats['guildName'] = guildName
if(('<br style="clear:both"/>' in line) and (gameName is not None)):
cr.writerow([user, gameName, extraStats['guildName'],
extraStats['lastOn'],extraStats['regOn']])