Dkt01
March 14, 2012, 10:51pm
1
Hi everyone,
I want to use the xml data from FRC-Spy to automatically update match results on our team website. My issue is I don’t know how to extract the xml data from FRC-Spy. I know you should be able to add “xml=2” to the end of the address to get all the match results in xml, but I can’t manage to get the actual information off the website. I’m using php with simple xml.
So far this is what I’m having trouble with:
$allmatches = simplexml_load_file("http://www.chiefdelphi.com/forums/frcspy.php?xml=2.xml");
This never actually loads the file so that I can use it. The server is running php 5.2.17.
Any suggestions or example code would be great, since I am pretty new to php.
Also, if I need to clarify anything, let me know.
The main problem is with your URL. ‘?xml=2.xml’ should just be ‘?xml=2’.
You can also add ‘&teams=4096’ after the 2 to filter to a specific team.
Here’s some sample code and a demo that (I think) provides the information you’re looking for.
Demo - I use team 27, since your team has no results in FRC-Spy yet - http://keatonismy.name/dev/frcspy.php
Code:
<?php
//$allmatches = simplexml_load_file("http://www.chiefdelphi.com/forums/frcspy.php?xml=2&teams=4096");
$allmatches = simplexml_load_file("http://www.chiefdelphi.com/forums/frcspy.php?xml=2&teams=27");
//print_r($allmatches);
$i = 0;
foreach ($allmatches as $row){
echo "<b>Event: </b>" . $allmatches->match$i]->event . "<br />";
echo "<b>Match Type: </b>" . $allmatches->match$i]->typ . "<br />";
echo "<b>Match No.: </b>" . $allmatches->match$i]->mch . "<br />";
echo "<b>Red 1: </b>" . $allmatches->match$i]->red1 . " ";
echo "<b>Red 2: </b>" . $allmatches->match$i]->red2 . " ";
echo "<b>Red 3: </b>" . $allmatches->match$i]->red3 . " <br />";
echo "<b>Blue 1: </b>" . $allmatches->match$i]->blue1 . " ";
echo "<b>Blue 2: </b>" . $allmatches->match$i]->blue2 . " ";
echo "<b>Blue 3: </b>" . $allmatches->match$i]->blue3 . " <br />";
echo "<b>Red Score: </b>" . $allmatches->match$i]->rfin . " ";
echo "<b>Blue Score: </b>" . $allmatches->match$i]->bfin . "<br />";
echo "<br />";
$i++;
}
?>
If you uncomment the print_r line, you’ll see the raw XML for your query.
Also, unless you’re set on coding this from scratch yourself, team 862 has a nice system for retrieving match results with simple configuration. Check out http://lightningrobotics.com/Contents/index.php?pagename=lrmrrs and the CD thread http://www.chiefdelphi.com/forums/showthread.php?t=104249
Dkt01
March 15, 2012, 11:46am
3
Thank you so much! I figured I made some simple mistake, but that’s part of learning.
Dkt01
March 15, 2012, 5:40pm
4
Actually, after more digging and debugging, my issue was that I can’t directly access external websites on this server (something like that). By using curl, my problem was solved. Thanks for the explanation on how to make FRC-spy filter by team, though.
Ether
March 15, 2012, 7:44pm
5
Just a heads-up: Before you invest too much time in this, you might want to read these posts:
Ether, Thanks for the data. The twitter data is worse than you thought. It is not just the Oregon and Traverse City data missing. If you look at individual events, you would find that it is missing a lot of matches (e.g. FL match 105, GG match 1-8,...