4

English Premier League Table

Posted in Internet by Qsiv 2088 days ago

Heres an updated English Premier League Table script. Change the file extension of EPL-table.txt to .py

If the table doesn't line up correctly, try changing the font.

To run the script, use the command "python [path to script file]" in a shell geeklet

#!/usr/bin/python

import elementtree.ElementTree as ET
import urllib2

url="http://www.footballwebpages.co.uk/league.xml?comp=1"

# make empty if no home/favorite team
hometeam = "Liverpool"

root = ET.parse(urllib2.urlopen(url)).getroot()

print "%3s %-20s %4s %4s %-3s" % ("POS","CLUB","PD","GD","PTS")

for team in root.findall('team'):
    pos = team.find('position').text
    name = team.find('name').text
    played = team.find('played').text
    GD = team.find('goalDifference').text
    points = team.find('points').text
    # if you'd like to shorten say West Bromwich Albion to WBA,
    # then you can uncomment the following:
    #if len(name.split(' ')) > 2:
    #   shortName = ""
    #   for word in name.split(' '):
    #       shortName += word[0]
    #   name = shortName
    if name == hometeam:
        # to change highlight color, change 41 to 41-47:
        # 41 - red
        # 42 - green
        # 44 - blue
        print "\033[1;41m%3s %-20s %4s %4s %3s \033[1;m" % (pos, name, played, GD, points)
    else:
        print "%3s %-20s %4s %4s %3s" % (pos, name, played, GD, points)

Comments

Log in to comment or register here.