Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How do I write a script to get this data from the FCC?

I am trying to use the skillset we learned in Making a Weather app to query the FCC database of licenses and return any radio stations within a certain distance of the user. The link they have says that the data files are so big many programs cannot open it (and i have not been able to) but if you are writing a script to extract the data to use the length provided. So that has me wondering how I can write a script to get the fields I need?

I'm assuming all I'd need would be callsign, frequency, and the coordinates to know if it is near or not? and a genre if they have it but it doesnt seem like they do.

really i know this is random but I really want to make this work so any help is really really appreciated!!!!

so far and I was querying a lowpower FM api but still having an error, then i realized it was not all the stations so i kinda gave up and started looking around and found these.

https://www.fcc.gov/developers/license-view-api https://www.fcc.gov/encyclopedia/fm-service-contour-data-points

3 Answers

So if you want to write a script, one alternative is to write the script in Groovy. Gradle supports Groovy which is scripting language. So what might help you is to write a small groovy script which does what you asked and have it in a grade file. Either the build.gradle or separate gradle file and invoke it in the build.gradle . I hope this answers your question.

Now that is if you want to do it in a script. Here is the link to Groovy: http://www.groovy-lang.org/learn.html

Now I haven't really tested this. But I found something that might help. Apparently Groovy 2.4 now supports Android. This means that you can write scripts in Android (or I think.). Here is a link:

http://www.mscharhag.com/2015/02/creating-android-apps-with-groovy.html

Anyways I hope this helps. And if you do try the 2nd method and it worked for you, it would be great if you could share that info as I would love to see it work.

I was able to get the data I need into an excel spreadsheet I believe and then used an online converter to make a ,json file. So now where do I upload it to, or can it stay in the app local folder and be accessed ?

and if so lets say I upload my json file, radioData.json to my domain... www.dredaycreative.com/radioData/radioData.json do I just use that URL to in the place of what I was using before to query this low powered FCC database??

'''

package com.dredaydesigns.radiostationfinder;

import android.R; import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.util.Log; import android.widget.TextView;

import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationServices; import com.squareup.okhttp.Call; import com.squareup.okhttp.Callback; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response;

import org.json.JSONException; import org.json.JSONObject;

import java.io.IOException;

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks {

public static final String TAG = MainActivity.class.getSimpleName();
private RadioData mRadioData;

private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;

TextView latitudeLabel;
TextView longitudeLabel;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_content);


    double latitude = 32;
    double longitude = -96;
    final RadioData[] mRadioData = new RadioData[1];
    String radioFinderURL = "http://data.fcc.gov/lpfmapi/rest/v1/lat/" + latitude + "/long/" + longitude + "?format=json&secondchannel=true";

    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder()
            .url(radioFinderURL)
            .build();
    Call call = client.newCall(request);
    call.enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {

        }

        @Override
        public void onResponse(Response response) throws IOException {
            try {
                String jsonData = response.body().string();
                Log.v(TAG,jsonData);
                if (response.isSuccessful()) {
                    mRadioData[0] = getCurrentDetails(jsonData);

                }

            } catch (IOException e) {
                Log.e(TAG, "Exception Caught: ", e);
            }
            catch(JSONException e){
                Log.e(TAG, "Exception Caught:", e);
            }
        }
    });

}

private RadioData getCurrentDetails(String jsonData) throws JSONException {
    JSONObject radioData = new JSONObject(jsonData);
    String callSign = radioData.getString("callsign");
    Log.i(TAG, "From JSON: " + callSign);

    JSONObject currently = radioData.getJSONObject("frequency");
    RadioData radioFinder = new RadioData();


        return new RadioData();


}

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener) this)
            .addApi(LocationServices.API)
            .build();


}


@Override
public void onConnected(Bundle bundle) {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        latitudeLabel.setText(String.valueOf(mLastLocation.getLatitude()));
        longitudeLabel.setText(String.valueOf(mLastLocation.getLongitude()));
    }
}


@Override
public void onConnectionSuspended(int i) {

}

}

'''

What if I use an html query link they have to dynamically change the URL to based on their longitude and latitude. how do i then get it to JSON?

im so out of my league ha i dont even know where to start