Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   Team List RSS? (http://www.chiefdelphi.com/forums/showthread.php?t=114725)

jasongb 07-03-2013 07:29

Team List RSS?
 
I'm looking to import a list of teams so I can populate this season's scouting database.

Does anyone know where I can get access to a list like that, in a format that lends itself to import?

I tried perusing https://my.usfirst.org/frc/tims, but it's currently broken with Error -9995. I also visited thebluealliance.com, but didn't see anything obvious there. Lastly, I did search the forum, but couldn't find anything relevant in a timely manner.

Any suggestions for a team list, and/or an event list, would be appreciated. Feel free to contact me via pm or via email: jason dot buxton @t gmail DOT com.

vinnie 07-03-2013 09:54

Re: Team List RSS?
 
Check out The FIRST Alliance API
http://thefirstalliance.com/apidoc.php

jasongb 07-03-2013 10:37

Re: Team List RSS?
 
Thanks!

Either I did it wrong, or something's amiss:

http://www.thefirstalliance.org/api/...ion=list-teams

This returns an error, although I think the complete XML document is included in the source....

[EDIT]:

Ah, it looks like some teams' names are unparseable in XML:

<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Gadget Engineering) in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Irish Bots in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Machines (M&amp;Ms) in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Bolts of Fury in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Bots in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Wayne County Robotics in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::addChild() [<a href='simplexmlelement.addchild'>simplexmlelement. addchild</a>]: unterminated entity reference Colts in <b>/homepages/26/d409590785/htdocs/first-api/first_scraper_web/api/api.xml.php</b> on line <b>36</b><br />

I'll work with the JSON syntax!

vinnie 07-03-2013 14:25

Re: Team List RSS?
 
Quote:

Originally Posted by jasongb (Post 1244834)
Thanks!
I'll work with the JSON syntax!

I generally find JSON data easier to work with.
If you're using Java I have a simple class to work with the FIRST Alliance APIs.

If you use this and don't use AppEngine, then you need to replace the JSON imports with JSON classes found elsewhere.
Code:

package org.team3309.scout;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import com.google.appengine.labs.repackaged.org.json.JSONArray;
import com.google.appengine.labs.repackaged.org.json.JSONException;
import com.google.appengine.labs.repackaged.org.json.JSONObject;

public class FirstAlliance {

        private static final String API = "http://www.thefirstalliance.org/api/api.json.php?action=";

        public static Event[] getEvents(String teamNumber) {
                Event[] competitions = new Event[0];
                String url = API + "team-events&team-number=3309";
                JSONArray events = getArray(url);
                competitions = new Event[events.length()];
                try {
                        for (int i = 0; i < events.length(); i++) {
                                JSONObject event = events.getJSONObject(i);
                                competitions[i] = new Event(event);
                        }
                } catch (JSONException ex) {
                        ex.printStackTrace();
                }
                return competitions;
        }
       
        public static Event getEventById(int id){
                String url = API+ "event-details&event-id="+id;
                JSONObject json = getJson(url);
                return new Event(json);
        }
       
        private static JSONArray getArray(String url) {
                try {
                        HttpURLConnection c = (HttpURLConnection) new URL(url)
                                        .openConnection();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(
                                        c.getInputStream()));
                        String line;
                        String input = "";
                        while ((line = reader.readLine()) != null)
                                input += line;
                        JSONObject json = new JSONObject(input);
                        return json.getJSONArray("data");
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                return null;
        }
       
        private static JSONObject getJson(String url){
                try {
                        HttpURLConnection c = (HttpURLConnection) new URL(url)
                                        .openConnection();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(
                                        c.getInputStream()));
                        String line;
                        String input = "";
                        while ((line = reader.readLine()) != null)
                                input += line;
                        JSONObject json = new JSONObject(input);
                        return json.getJSONObject("data");
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                return null;
        }

        public static class Event{
               
                private String name;
                private int id;
                private JSONArray rankingsJson;
                private ArrayList<Ranking> rankings;
               
                private Event(JSONObject json){
                        this.name = json.optString("name");
                        this.id = json.optInt("id");
                        this.rankingsJson = json.optJSONArray("rankings");
                }
                public String getName(){
                        return name;
                }
                public int getId(){
                        return id;
                }
                public ArrayList<Ranking> getRankings(){
                        if(rankings != null)
                                return rankings;
                        ArrayList<Ranking> list = new ArrayList<Ranking>();
                        for(int i=0; i<rankingsJson.length(); i++){
                                JSONObject json = rankingsJson.optJSONObject(i);
                                list.add(new Ranking(json.optString("Team"), json.optInt("Rank"), json.optString("Record (W-L-T)")));
                        }
                        return list;
                }
               
                public String toString(){
                        return name;
                }
        }
       
        public static class Ranking{
               
                private String team, record;
                private int ranking;
               
                private Ranking(String team, int ranking, String record){
                        this.team = team;
                        this.ranking = ranking;
                        this.record = record;
                }
               
                public String getRecord(){
                        return record;
                }
               
                public int getWins(){
                        return Integer.parseInt(record.substring(0, record.indexOf("-")));
                }
               
                public int getLosses(){
                        return Integer.parseInt(record.substring(record.indexOf("-")+1, record.indexOf("-", record.indexOf("-")+1)));
                }
               
                public int getTies(){
                        return Integer.parseInt(record.substring(record.lastIndexOf("-")+1));
                }
               
                public String getTeam(){
                        return team;
                }
               
                public int getRank(){
                        return ranking;
                }
        }
}


jasongb 08-03-2013 00:17

Re: Team List RSS?
 
I'm exploring the rest of the API, and I was wondering if you had a guide to all of the acronyms used in the 'rankings'?

vinnie 08-03-2013 00:31

Re: Team List RSS?
 
Quote:

Originally Posted by jasongb (Post 1245086)
I'm exploring the rest of the API, and I was wondering if you had a guide to all of the acronyms used in the 'rankings'?

Can you give me an example so that I can try to help you?

jasongb 08-03-2013 05:54

Re: Team List RSS?
 
Sure:

{"Rank":"2","DQ":"0","CP":"0","QS":"18.00","BP":"2 10.00","TP":"200.00","Record (W-L-T)":"9-1-0","HP":"214.00","Team":"138","Played":"10"}

DQ? CP? QS? BP? TP? HP?

John Sabath 08-03-2013 16:36

Re: Team List RSS?
 
Here are the tab separated lists from FIRST

Teams
https://my.usfirst.org/frc/scoring/i...?page=teamlist

Events
https://my.usfirst.org/frc/scoring/i...page=eventlist


All times are GMT -5. The time now is 07:34.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi