Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit f78466f1a8811cb599cf184904b2751312751d4c @adelevie adelevie committed Apr 12, 2012
Showing with 75 additions and 0 deletions.
  1. +19 −0 README.md
  2. +56 −0 client.py
@@ -0,0 +1,19 @@
+The FCC Content API allows you to programmatically access much of the content accessible on [FCC.gov](http://fcc.gov).
+
+fcc-content-api-python is a lightweight Python wrapper for the Federal Communication Commission's Content API.
+
+The FCC Content API is powered by the [Drupal Content API Module](http://drupal.org/project/contentapi).
+
+## Usage
+
+First, familiarize yourself with the [FCC Content API REST Documentation](http://www.fcc.gov/developer/fcc-content-api).
+
+Query parameters map 1-to-1 to the options listed in the link above.
+
+```python
+Content().where({"search_string":"broadband"}).where({"limit":1}).all().text
+```
+
+## More Info
+
+For more information, please visit the [FCC's Developers page](http://www.fcc.gov/developers) and the [FCC's Github page](http://github.com/fcc).
@@ -0,0 +1,56 @@
+import requests
+
+class Content(object):
+ def where(self, params={}):
+ return Query(self).where(params)
+
+ def all(self):
+ return Query(self).all()
+
+class Query(object):
+ def __init__(self, klass):
+ self._klass = klass
+ self._client = Client()
+ self._criteria = None
+ self._request = None
+
+ def criteria(self):
+ if not self._criteria:
+ self._criteria = {}
+ return self._criteria
+
+ def where(self, params={}):
+ self.criteria().update(params)
+ return self
+
+ def all(self):
+ return self.execute()
+
+ def request(self):
+ if not self._request:
+ self._request = self._client.all(self.criteria())
+ return self._request
+
+ def execute(self):
+ return self.request().perform()
+
+class Client(object):
+ def __init__(self):
+ self._domain = "http://www.fcc.gov/api"
+ self._params = None
+ self._url = None
+
+ def get(self, id):
+ self._url = "%(domain)s/content/%(id)s.json" % {'id':id, 'domain':self._domain}
+ return self
+
+ def all(self, params={}):
+ self._params = params
+ self._url = "%(domain)s/content.json?" % {'domain':self._domain}
+ return self
+
+ def perform(self):
+ return requests.get(self._url, params=self._params)
+
+# example:
+# print Content().where({"search_string":"broadband"}).where({"limit":1}).all().text

0 comments on commit f78466f

Please sign in to comment.