4

Spanish Football - La Liga

Posted in Internet by finster 1147 days ago

Here's a script to show a summary of La Liga. Save it somewhere (such as Documents/laliga.py).

Use the command "python /Users/xxxx/Documents/laliga.py" to run it.

#!/usr/bin/python

import urllib2
from xml.dom.minidom import parseString

hometeam="Barcelona" # Replace this with your team

url="http://www.footbo.com/widgets/xml/LeagueTable.aspx?id=193770"

file = urllib2.urlopen(url)
data = file.read()
file.close()
data = data.replace(hometeam, hometeam.upper())

#parse xml
dom = parseString(data)

print "POS CLUB                 PLD   GD PTS"

#loop through <entry> elements
entry=dom.getElementsByTagName('LeagueTableRow')
for node in entry:
    position=node.getAttribute('Position')
    name=node.getAttribute('TeamName')
    played=node.getAttribute('GamesPlayed')
    goalDifference=node.getAttribute('GoalsDifference')
    points=node.getAttribute('Points')

    print "%3s %-20s %3s %4s %3s" % (position, name, played, goalDifference, points)

Geeklet files to download

Comments

User Avatar
finster 1146 days ago
You can also change the URL to get other league tables. For example: -

# Serie A

url="http://www.footbo.com/widgets/xml/LeagueTable.aspx?id=193729"

# Bundesliga

url="http://www.footbo.com/widgets/xml/LeagueTable.aspx?id=193709"

# English Championship

url="http://www.footbo.com/widgets/xml/LeagueTable.aspx?id=193699"

# English Premier League

url="http://www.footbo.com/widgets/xml/LeagueTable.aspx?id=193698"

These URL's can be found by going to the league on footbo.com, looking at the HTML source and searching for "LeagueTable.aspx?id=".

Hope this helps somebody!
User Avatar
olivierdeen 1146 days ago
I really like the idea but i can't get the lines right...

Help?
User Avatar
finster 1146 days ago
Sorry, I don't understand what your problem is?
User Avatar
matt 1145 days ago
Try a fixed width font? Like Courier or Menlo.
User Avatar
olivierdeen 1145 days ago
Thnx matt that works!
User Avatar
shakeya 1144 days ago
Awesome work ! Love it !

only shows the top 9 teams in the German Bundesliga though.

Any solution to that ?

thx
User Avatar
finster 1142 days ago
@shakeya - works fine for me - all 18 teams are displayed. Does it run OK via the command line (save it as bundesliga.py and then run via the terminal app with "python bundesliga.py")
User Avatar
n1mie 965 days ago
Can't get it to work.

/usr/bin/python runs Python v2.7. I also have Python 3.2 installed and have tried that. Python 3.2 runs with fewer errors, but it still has errors (mostly associated with the print commands).

No idea how proceed as I'm not a Python guy.

Log in to comment or register here.