Skip to content
Browse files

Broke into 2 files

  • Loading branch information...
1 parent 036d84c commit 3ca029c6f3f9fce6bbf1d6462240e7f0e24cc490 @johnfn johnfn committed Apr 16, 2011
Showing with 19 additions and 49 deletions.
  1. 0 __init__.py
  2. +2 −20 broadband_api.py
  3. +0 −29 fcc_api.py
  4. +17 −0 generic_api.py
  5. BIN generic_api.pyc
View
0 __init__.py
No changes.
View
22 broadband_api.py
@@ -1,25 +1,7 @@
-import urllib
-import json
-
-# Inheritable class to perform requests to generic APIs.
-class BaseAPIRequest:
- def __init__(self, url):
- self.url = url
-
- #Inherit this method to describe how to format URLs.
- def format_url(self):
- pass
-
- # Requests the API and returns the JSON object.
- def request(self, **args):
- self.format_url(**args)
- object = json.loads("".join([l for l in urllib.urlopen(self.url)]))
- return object
-
-
-
+from generic_api import *
# Simple Python wrapper around the Broadband API provided by the FCC.
+
class BroadbandApi(BaseAPIRequest):
def __init__(self):
BaseAPIRequest.__init__(self, "http://data.fcc.gov/api/speedtest/find?latitude=%s&longitude=%s&format=json")
View
29 fcc_api.py
@@ -1,29 +0,0 @@
-import urllib
-import json
-
-class BaseAPIRequest:
- def __init__(self):
- pass
-
- def request(self, **args):
- pass
-
-# Simple Python wrapper around the Broadband API provided by the FCC.
-class BroadbandApi(BaseAPIRequest):
- def __init__(self):
- pass
-
- # Pass in LATitude and LONGitude into this function and get back a JSON object
- # indicating measured broadband speed.
- def request(self, **args):
- url = "http://data.fcc.gov/api/speedtest/find?latitude=%s&longitude=%s&format=json"
- url = url % (args['lat'], args['long'])
-
- object = json.loads("".join([l for l in urllib.urlopen(url)]))
- return object
-
-
-# Demonstration of how to use BroadbandApi
-if __name__ == "__main__":
- bb = BroadbandApi()
- print bb.request(lat=37, long=-122) # (Should be San Francisco)
View
17 generic_api.py
@@ -0,0 +1,17 @@
+import urllib
+import json
+
+# Inheritable class to perform requests to generic APIs.
+class BaseAPIRequest:
+ def __init__(self, url):
+ self.url = url
+
+ #Inherit this method to describe how to format URLs.
+ def format_url(self):
+ pass
+
+ # Requests the API and returns the JSON object.
+ def request(self, **args):
+ self.format_url(**args)
+ object = json.loads("".join([l for l in urllib.urlopen(self.url)]))
+ return object
View
BIN generic_api.pyc
Binary file not shown.

0 comments on commit 3ca029c

Please sign in to comment.
Something went wrong with that request. Please try again.