diff options
| author | jason | 2015-10-28 18:42:36 -0600 |
|---|---|---|
| committer | jason | 2015-10-28 18:42:36 -0600 |
| commit | cccc599be2ba004bd521e3c99d274eaf5e385313 (patch) | |
| tree | aa84401414f951458a563ccb5b0a707709072240 /geeklets/epl_table.py | |
| parent | 781ad5cd294e3b8a519b87ed7dd74ec1b91f52fe (diff) | |
| download | dotfiles-cccc599be2ba004bd521e3c99d274eaf5e385313.tar.gz dotfiles-cccc599be2ba004bd521e3c99d274eaf5e385313.zip | |
add epl table geeklet
Diffstat (limited to 'geeklets/epl_table.py')
| -rw-r--r-- | geeklets/epl_table.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/geeklets/epl_table.py b/geeklets/epl_table.py new file mode 100644 index 0000000..5251bac --- /dev/null +++ b/geeklets/epl_table.py | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | from xml.etree import ElementTree as ET | ||
| 4 | import urllib2 | ||
| 5 | |||
| 6 | url="http://www.footballwebpages.co.uk/league.xml?comp=1" | ||
| 7 | |||
| 8 | # make empty if no home/favorite team | ||
| 9 | hometeam = "Liverpool" | ||
| 10 | |||
| 11 | root = ET.parse(urllib2.urlopen(url)).getroot() | ||
| 12 | |||
| 13 | print "%3s %-20s %4s %4s %-3s" % ("POS","CLUB","PD","GD","PTS") | ||
| 14 | |||
| 15 | for team in root.findall('team'): | ||
| 16 | pos = team.find('position').text | ||
| 17 | name = team.find('name').text | ||
| 18 | played = team.find('played').text | ||
| 19 | GD = team.find('goalDifference').text | ||
| 20 | points = team.find('points').text | ||
| 21 | # if you'd like to shorten say West Bromwich Albion to WBA, | ||
| 22 | # then you can uncomment the following: | ||
| 23 | #if len(name.split(' ')) > 2: | ||
| 24 | # shortName = "" | ||
| 25 | # for word in name.split(' '): | ||
| 26 | # shortName += word[0] | ||
| 27 | # name = shortName | ||
| 28 | if name == hometeam: | ||
| 29 | # to change highlight color, change 41 to 41-47: | ||
| 30 | # 41 - red | ||
| 31 | # 42 - green | ||
| 32 | # 44 - blue | ||
| 33 | print "\033[1;41m%3s %-20s %4s %4s %3s \033[0;49m" % (pos, name, played, GD, points) | ||
| 34 | else: | ||
| 35 | print "%3s %-20s %4s %4s %3s" % (pos, name, played, GD, points) | ||
| 36 | |||