-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.py
More file actions
34 lines (29 loc) · 962 Bytes
/
tables.py
File metadata and controls
34 lines (29 loc) · 962 Bytes
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
#
# $Id$
#
from BeautifulSoup import BeautifulSoup
import sys, string
import HTMLParser
from utils import commaSep
parser = HTMLParser.HTMLParser()
soup = BeautifulSoup(file(sys.argv[1]).read())
#def commaSep(items):
# return ",".join(['"' + i + '"' for i in items])
for division in soup.findAll('tr', {'bgcolor':'silver'}):
parent = division.parent
rows = parent.findAll('tr')
division_name = rows[0].contents[0].contents[0].contents[0]
division = division_name.split(' ')[1]
headers = [str(cell.contents[0]) for cell in rows[0].findAll('b')]
headers[0] = 'Team Name'
headers.append('Division')
headers.append('Position')
if division == "1":
print commaSep(headers)
position = 1
for row in rows[1:]:
data = [parser.unescape(str(cell.contents[0])) for cell in row.findAll('td') if str(cell.contents[0]) != ' ']
data.append(division)
data.append(str(position))
position = position + 1
print commaSep(data)