-
Notifications
You must be signed in to change notification settings - Fork 5
/
groups.py
executable file
·67 lines (49 loc) · 1.58 KB
/
groups.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
#!/usr/bin/env python3
"""Script for scraping some ESPN Tournament Challenge groups from:
- Top Groups: /topGroups
- Group Directory: /groupdir
- Suggested Groups: /groupfind
Base url: http://games.espn.go.com/tournament-challenge-bracket/2015/en/
Given group IDs, we can fetch brackets. Check `brackets.py`.
I already ran this and saved the output under `groups.txt`; so I do not
suggest you run this again unless necessary.
"""
import os
import re
import requests
host = 'http://games.espn.go.com/tournament-challenge-bracket/2015/en/'
r = re.compile('groupID=(\d+)')
def _fetch(path):
resp = requests.get(host + path)
return r.findall(resp.text)
def _groupdir():
url = 'groupdir?&xhr=1&groupType=0&isLocked=0&access='
groups = set()
# Enumerate through private and public access groups.
for i in range(1,3):
u = url + str(i) + '&objectStart='
# ESPN caps at 1000 groups.
for t in range(0, 1000, 30):
g = _fetch(u + str(t))
groups.update(g)
return groups
def _topgroups():
url = 'topGroups?xhr=1&groupType='
groups = set()
for t in range(3):
g = _fetch(url + str(t))
groups.update(g)
return groups
def _groupfind():
g = _fetch('groupfind')
return set(g)
def scrape_groups(filename='groups.txt'):
g = _groupfind()
g.update(_topgroups())
g.update(_groupdir())
g = sorted(map(int, g))
with open(filename, 'w') as f:
f.write(os.linesep.join(map(str, g)))
print('Output written to {}'.format(filename))
if __name__ == '__main__':
scrape_groups()