Sep 18 2006, 05:43 PM
Post
#1
|
|
![]() Group: Members Posts: 10,620 Joined: 23-February 06 From: Houston, TX Member No.: 48 |
anybody know of a sports scores data feed that's free?
|
|
|
|
![]() |
Sep 18 2006, 05:56 PM
Post
#2
|
|
![]() Group: Admin Posts: 3,403 Joined: 23-February 06 From: PDX/TXL Member No.: 35 |
http://www.sportznetwork.com/scores/code.htm is the only thing I can find that's even worth looking at. Most of the sports feeds are related to news... They want you to visit their sites to see the actual scores. I'll keep my eyes open though.
-------------------- "There is a level of cowardice lower than that of the conformist: that of the fashionable non-conformist." |
|
|
|
Sep 18 2006, 06:23 PM
Post
#3
|
|
![]() Group: Members Posts: 10,620 Joined: 23-February 06 From: Houston, TX Member No.: 48 |
yeah i've looked for this stuff before and most of it costs money... i may just write something that parses up the espn scoreboard pages
|
|
|
|
Sep 18 2006, 06:28 PM
Post
#4
|
|
![]() Group: Members Posts: 5,275 Joined: 22-February 06 Member No.: 2 |
QUOTE (impala454 @ Sep 18 2006, 06:23 PM) yeah i've looked for this stuff before and most of it costs money... i may just write something that parses up the espn scoreboard pages you should write a firefox plugin that scrolls whatever scores you want and then sell it |
|
|
|
Sep 18 2006, 09:11 PM
Post
#5
|
|
![]() Group: Members Posts: 10,620 Joined: 23-February 06 From: Houston, TX Member No.: 48 |
success!
I'll use the data structures in the thing but I figured I'd output to a csv file in case any of you wanted to use it too. download it here (you'll prob need the .net framework if you don't have it) it's a console app, do: EspnScoreboardParser.exe InputFile.txt OutputFile.csv where InputFile.txt is the source HTML from an ESPN CFB page like this. You'll browse to the page, go to view->source, then copy paste the HTML to a text file as your input. The output file is csv with the first row as the header. The rank of the team is -1 if they're unranked. If you have any probs let me know... it wouldn't surprise me.. I threw some quick shit code together. obviously lots more could be done to extend it but all I'm doing is dumping this data to SQL so I don't care how pretty it is. |
|
|
|
Sep 18 2006, 09:27 PM
Post
#6
|
|
![]() Group: Admin Posts: 3,403 Joined: 23-February 06 From: PDX/TXL Member No.: 35 |
QUOTE (impala454 @ Sep 18 2006, 09:11 PM) success! I'll use the data structures in the thing but I figured I'd output to a csv file in case any of you wanted to use it too. download it here (you'll prob need the .net framework if you don't have it) it's a console app, do: EspnScoreboardParser.exe InputFile.txt OutputFile.csv where InputFile.txt is the source HTML from an ESPN CFB page like this. You'll browse to the page, go to view->source, then copy paste the HTML to a text file as your input. The output file is csv with the first row as the header. The rank of the team is -1 if they're unranked. If you have any probs let me know... it wouldn't surprise me.. I threw some quick shit code together. obviously lots more could be done to extend it but all I'm doing is dumping this data to SQL so I don't care how pretty it is. Can you post the source? I'll port it to Python or something so that it will run on other OS's -------------------- "There is a level of cowardice lower than that of the conformist: that of the fashionable non-conformist." |
|
|
|
Sep 18 2006, 09:51 PM
Post
#7
|
|
![]() Group: Members Posts: 10,620 Joined: 23-February 06 From: Houston, TX Member No.: 48 |
like i said... it's quick, shit code. not pretty but it works. done in C#.NET
CODE using System;
using System.Collections.Generic; using System.Collections; using System.Text; using System.IO; using System.Data.SqlClient; using System.Data; namespace EspnScoreboardParser { class Program { public struct Game { public string HomeTeam; public string AwayTeam; public int HomeTeamScore; public int AwayTeamScore; public int HomeTeamRank; public int AwayTeamRank; public DateTime DateOfGame; } static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: EspnScoreboardParser.exe InputFile.txt OutputFile.txt"); return; } StringBuilder input = new StringBuilder(); StreamReader sr = new StreamReader(args[0]); input.Append(sr.ReadToEnd()); ArrayList datechangeindexes = new ArrayList(); ArrayList games = new ArrayList(); ArrayList teams = new ArrayList(); ArrayList homeranks = new ArrayList(); ArrayList awayranks = new ArrayList(); ArrayList hometeams = new ArrayList(); ArrayList awayteams = new ArrayList(); ArrayList awayscores = new ArrayList(); ArrayList homescores = new ArrayList(); ArrayList gamedates = new ArrayList(); int tmpindex = 0; int previndex = 0; int count = 0; string tmpstr = input.ToString(); DateTime startdatetime = new DateTime(); while (tmpindex >= 0) { tmpindex = tmpstr.IndexOf("dateChange", previndex); previndex = tmpindex + 1; count++; if (count <= 1) { int enddatestr = tmpstr.IndexOf("-</div", tmpindex); enddatestr = enddatestr - tmpindex - 13; string tmpdateparse = tmpstr.Substring(tmpindex + 13, enddatestr); DateTime.TryParse(tmpdateparse,out startdatetime); } else { if(tmpindex > 0) datechangeindexes.Add(tmpindex); } //Console.WriteLine(tmpindex); } count = 0; tmpindex = 0; previndex = 0; int tmpstartindex = 0; DateTime currentgamedate = startdatetime; int gametogggle = 0; while(tmpindex >= 0) { tmpindex = tmpstr.IndexOf("teamId=", previndex); previndex = tmpindex+1; try { tmpstartindex = tmpstr.IndexOf("\">", tmpindex) + 2; } catch(Exception ex1) { //Console.WriteLine(ex1.Message); break; } string stringtoparse = tmpstr.Substring(tmpstartindex, tmpstr.IndexOf("</a>", tmpindex) - tmpstartindex); for(int dateindex=datechangeindexes.Count-1; dateindex>=0; dateindex--) { if (tmpindex >= (int)datechangeindexes[dateindex]) { currentgamedate = startdatetime.AddDays(dateindex+1); break; } else currentgamedate = startdatetime; } gametogggle++; int rank = -1; if (stringtoparse.Contains("(")) { string tmprank = stringtoparse.Substring(stringtoparse.IndexOf("(") + 1, stringtoparse.IndexOf(")") - stringtoparse.IndexOf("(")-1); if(Int32.TryParse(tmprank, out rank)) stringtoparse = stringtoparse.Substring(stringtoparse.IndexOf(")") + 1).Trim(); } if (gametogggle % 2 == 1) { //Console.WriteLine(currentgamedate.ToString("ddd") + ": A: " + stringtoparse); awayteams.Add(stringtoparse); awayranks.Add(rank); gamedates.Add(currentgamedate); } else { //Console.WriteLine(currentgamedate.ToString("ddd") + ": H: " + stringtoparse + "\n================="); hometeams.Add(stringtoparse); homeranks.Add(rank); } } //Console.WriteLine("------------------------------------------------------------"); count = 0; tmpindex = 0; previndex = 0; tmpstartindex = 0; currentgamedate = startdatetime; gametogggle = 0; while (tmpindex >= 0) { tmpindex = tmpstr.IndexOf("atot", previndex); previndex = tmpindex + 1; try { tmpstartindex = tmpstr.IndexOf("\">", tmpindex) + 2; } catch(Exception ex2) { //Console.WriteLine(ex2.Message); break; } string stringtoparse = tmpstr.Substring(tmpstartindex, tmpstr.IndexOf("</td>", tmpindex) - tmpstartindex); for (int dateindex = datechangeindexes.Count - 1; dateindex >= 0; dateindex--) { if (tmpindex >= (int)datechangeindexes[dateindex]) { currentgamedate = startdatetime.AddDays(dateindex + 1); break; } else currentgamedate = startdatetime; } awayscores.Add(Convert.ToInt32(stringtoparse)); //Console.WriteLine(currentgamedate.ToString("ddd") + ": A: " + stringtoparse); } count = 0; tmpindex = 0; previndex = 0; tmpstartindex = 0; currentgamedate = startdatetime; gametogggle = 0; while (tmpindex >= 0) { tmpindex = tmpstr.IndexOf("htot", previndex); previndex = tmpindex + 1; try { tmpstartindex = tmpstr.IndexOf("\">", tmpindex) + 2; } catch(Exception ex3) { //Console.WriteLine(ex3.Message); break; } string stringtoparse = tmpstr.Substring(tmpstartindex, tmpstr.IndexOf("</td>", tmpindex) - tmpstartindex); for (int dateindex = datechangeindexes.Count - 1; dateindex >= 0; dateindex--) { if (tmpindex >= (int)datechangeindexes[dateindex]) { currentgamedate = startdatetime.AddDays(dateindex + 1); break; } else currentgamedate = startdatetime; } homescores.Add(Convert.ToInt32(stringtoparse)); //Console.WriteLine(currentgamedate.ToString("ddd") + ": H: " + stringtoparse); } Game tmpgame = new Game(); for (int x = 0; x < homescores.Count; x++) { tmpgame = new Game(); tmpgame.AwayTeam = (string)awayteams[x]; tmpgame.HomeTeam = (string)hometeams[x]; tmpgame.AwayTeamScore = (int)awayscores[x]; tmpgame.HomeTeamScore = (int)homescores[x]; tmpgame.AwayTeamRank = (int)awayranks[x]; tmpgame.HomeTeamRank = (int)homeranks[x]; tmpgame.DateOfGame = (DateTime)gamedates[x]; games.Add(tmpgame); } foreach(Game g in games) { Console.WriteLine("{6}: ({5}){2}={3} @ ({4}){0}={1}", g.HomeTeam, g.HomeTeamScore, g.AwayTeam, g.AwayTeamScore, g.HomeTeamRank, g.AwayTeamRank, g.DateOfGame.ToString("ddd, MMM dd, yyyy")); } Console.WriteLine("{0} games parsed.\nChuck rules! ESPN drools!", games.Count); StreamWriter sw = new StreamWriter(args[1]); sw.WriteLine("Date,HomeRank,HomeTeam,HomeScore,AwayRank,AwayTeam,AwayScore"); foreach (Game g in games) { sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", g.DateOfGame.ToString("yyyy-MM-dd"), g.HomeTeamRank, g.HomeTeam, g.HomeTeamScore, g.AwayTeamRank, g.AwayTeam, g.AwayTeamScore); } sw.Close(); SqlConnection db = new SqlConnection("younoaccessmysqlserver!!"); db.Open(); foreach (Game g in games) { InsertSql(db, g); } db.Close(); } public static void InsertSql(SqlConnection db, Game g) { StringBuilder insert = new StringBuilder(); insert.AppendFormat("insert into atablenameusedtobehere values ('{0}', '{1}')", g.HomeTeam, g.AwayTeam); SqlCommand comm = new SqlCommand(insert.ToString(), db); comm.ExecuteNonQuery(); } } } |
|
|
|
Sep 18 2006, 09:51 PM
Post
#8
|
|
![]() Group: Members Posts: 10,620 Joined: 23-February 06 From: Houston, TX Member No.: 48 |
basically just looks for key div classes or html pieces that indicate certain game data. feel free to do whatever with it, but if you add cool stuff post it back up here!
|
|
|
|
Sep 18 2006, 10:11 PM
Post
#9
|
|
![]() Group: Admin Posts: 3,403 Joined: 23-February 06 From: PDX/TXL Member No.: 35 |
Cool. I'll have some time tomorrow to play with it. Thanks for posting it up.
-------------------- "There is a level of cowardice lower than that of the conformist: that of the fashionable non-conformist." |
|
|
|
Sep 19 2006, 12:06 AM
Post
#10
|
|
![]() Retired Funk-bringer Group: Moderators Posts: 2,656 Joined: 22-February 06 From: Dallas Member No.: 14 |
this has serious potential for niftiness.
I've been toying with the idea of buying one of those LED scroller thingies, and I think it'd be tight to hook one up to my PC running this script or a variant of it. -------------------- WAIT. I'm not finished.
|
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 20th August 2026 - 03:39 PM |