ECFS Public API

(0 reviews)

Download Plan

The FCC has enhanced the API to make data extraction simpler and more efficient. This new feature is called the “DownloadPlan”. You no longer need to specify offsets/limits. You now have the ability to customize your query with all the necessary parameters to extract data, as needed. Sample API Calls:

Example API call:

https://publicapi.fcc.gov/ecfs/filings?api_key=[yourkey].&proceedings.name=17-108

Download plan for this API call:

https://publicapi.fcc.gov/ecfs/filings?api_key=[yourkey].&proceedings.name=17-108=downloadplan

Other examples:

{
  "filings": [],
  "aggregations": {
    "download_plan": {
      "buckets": [
        {
          "key_as_string": "[gte]2017-04-27T13:20:00.000Z[lt]2017-04-29T19:31:00.000Z",
          "doc_count": 9995,
          "key": 1493299200000,
          "suggested_api_call": [
           "https://publicapi.fcc.gov/ecfs/filings?proceedings.name=17-108&date_submission=[gte]2017-04-27T13:20:00.000Z[lt]2017-04-29T19:31:00.000Z&sort=date_submission,ASC&limit=9995"
          ]
        },
        {
          "key_as_string": "[gte]2017-04-29T19:31:00.000Z[lt]2017-05-02T00:10:00.000Z",
          "doc_count": 9971,
          "key": 1493494260000,
          "suggested_api_call": [
            "https://publicapi.fcc.gov/ecfs/filings?proceedings.name=17-108&date_submission=[gte]2017-04-29T19:31:00.000Z[lt]2017-05-02T00:10:00.000Z&sort=date_submission,ASC&limit=9971"
          ]
        },
...

Python Script Example:

# ------------------------------------------------------------------
# export of FCC filings using a download plan
# example usage for proceeding 17-108
# Usage:
# python getDownloadPlan.py {APIKey}
# ------------------------------------------------------------------
import json
import requests
import sys


#config
APIUrl = "https://publicapi.fcc.gov/ecfs/"

try:  #check for  api key
    api_key = sys.argv[1]
except (ValueError, IndexError):
    raise ValueError("API key is not supplied  ")

APIKey = "&api_key="+api_key
#customize the query
url=APIUrl +'filings?proceedings.name=17-108'+'&type=downloadplan'+ APIKey
print url
response = requests.get(url)
parsed = response.json()

#get download plan in json
filename = 'downloadplan.json'
with open('downloadplan.txt', 'w') as outfile:
    json.dump(parsed, outfile)

#for each bucket iterate over list of suggested api calls.
for doc in parsed['aggregations']['download_plan']['buckets']:
    file_slice = str(doc['key'])
    count=0
    #print(json.dumps(doc, indent=4,sort_keys=True))
    if doc['suggested_api_call']:
        for api_call in doc['suggested_api_call']:
            ++count
            api_call_key=api_call+APIKey
            file_slice_key = str(doc['key'])+str(count)+'.txt'
            print '--> ' + api_call_key
            slice_req = requests.get(api_call_key, stream=True)
            with open(file_slice_key, 'wb') as fd:
               for chunk in slice_req.iter_content(chunk_size=128):
                   if chunk:
                       fd.write(chunk)

            fd.close()
# End While

# Save  the  file

Reviews