Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ohhhh welllll

  • Loading branch information...
commit b8dcf827188a5719aa6c31786552311cf30b7b5f 1 parent d9c24e1
quadrismegistus authored
Showing with 974 additions and 0 deletions.
  1. +45 −0 build/lib.linux-x86_64-2.6/python-fcc/FRNConversionsAPI.py
  2. 0  build/lib.linux-x86_64-2.6/python-fcc/__init__.py
  3. +13 −0 build/lib.linux-x86_64-2.6/python-fcc/block_conversion_api.py
  4. +15 −0 build/lib.linux-x86_64-2.6/python-fcc/broadband_api.py
  5. +130 −0 build/lib.linux-x86_64-2.6/python-fcc/generic_api.py
  6. +22 −0 build/lib.linux-x86_64-2.6/python-fcc/license_view_api.py
  7. +33 −0 build/lib.linux-x86_64-2.6/python-fcc/sba_businesses_api.py
  8. +35 −0 build/lib.linux-x86_64-2.6/python-fcc/sba_loans_grants_api.py
  9. 0  build/lib.linux-x86_64-2.6/python-fcc/tests/__init__.py
  10. +5 −0 build/lib.linux-x86_64-2.6/python-fcc/tests/__main__.py
  11. +105 −0 build/lib.linux-x86_64-2.6/python-fcc/tests/testcases.py
  12. BIN  dist/python_fcc-0.1-py2.6.egg
  13. +45 −0 python-fcc/FRNConversionsAPI.py
  14. 0  python-fcc/__init__.py
  15. +13 −0 python-fcc/block_conversion_api.py
  16. +15 −0 python-fcc/broadband_api.py
  17. 0  python-fcc/build/lib.linux-x86_64-2.6/tests/__init__.py
  18. +5 −0 python-fcc/build/lib.linux-x86_64-2.6/tests/__main__.py
  19. +105 −0 python-fcc/build/lib.linux-x86_64-2.6/tests/testcases.py
  20. BIN  python-fcc/dist/python_fcc-0.1-py2.6.egg
  21. +130 −0 python-fcc/generic_api.py
  22. +22 −0 python-fcc/license_view_api.py
  23. +10 −0 python-fcc/python_fcc.egg-info/PKG-INFO
  24. +8 −0 python-fcc/python_fcc.egg-info/SOURCES.txt
  25. +1 −0  python-fcc/python_fcc.egg-info/dependency_links.txt
  26. +1 −0  python-fcc/python_fcc.egg-info/top_level.txt
  27. +33 −0 python-fcc/sba_businesses_api.py
  28. +35 −0 python-fcc/sba_loans_grants_api.py
  29. 0  python-fcc/tests/__init__.py
  30. +5 −0 python-fcc/tests/__main__.py
  31. +105 −0 python-fcc/tests/testcases.py
  32. +10 −0 python_fcc.egg-info/PKG-INFO
  33. +16 −0 python_fcc.egg-info/SOURCES.txt
  34. +1 −0  python_fcc.egg-info/dependency_links.txt
  35. +1 −0  python_fcc.egg-info/top_level.txt
  36. +10 −0 setup.py
View
45 build/lib.linux-x86_64-2.6/python-fcc/FRNConversionsAPI.py
@@ -0,0 +1,45 @@
+from generic_api import *
+import urllib,json
+
+
+# Simple Python wrapper around the Broadband API provided by the FCC.
+
+class FRNConversionsAPI(GenericAPI):
+ """
+ FRNConversionsAPI:
+ - an API to access information about broadband provides.
+ - original API: http://reboot.fcc.gov/developer/frn-conversions-api
+
+ - methods:
+ -- getList(stateCode, multi)
+ takes stateCode=IL or stateCode=17 (FIPS code),
+ (optional) multi=Yes or multi=No to signify whether to include FRNs also operating outside this state.
+
+ -- getInfo(frn)
+ takes frn='0017855545' (FRN id)
+ """
+
+
+ def __init__(self):
+ apis= [
+ ('getList', 'http://data.fcc.gov/api/frn/getList'),
+ ('getInfo', 'http://data.fcc.gov/api/frn/getInfo')]
+
+ GenericAPI.__init__(self,apis)
+
+
+if __name__ == "__main__":
+ bb = FRNConversionsAPI()
+
+ x=bb.getList(stateCode='IL')
+ print type(x)
+ print len(x)
+ print x.keys()
+
+ #print x
+
+ print
+ x=bb.getInfo(frn='0017855545')
+ print type(x)
+ print len(x)
+ print x
View
0  build/lib.linux-x86_64-2.6/python-fcc/__init__.py
No changes.
View
13 build/lib.linux-x86_64-2.6/python-fcc/block_conversion_api.py
@@ -0,0 +1,13 @@
+from generic_api import *
+
+# Simple Python wrapper around the Block Conversion API provided by the FCC.
+
+class BlockConversionAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, [("get_block", "http://data.fcc.gov/api/block/find")])
+
+
+# Sample use of BlockConversionAPI
+if __name__ == "__main__":
+ bc = BlockConversionAPI()
+ print bc.get_block(lat=41, long=-87) # (Should be San Francisco)
View
15 build/lib.linux-x86_64-2.6/python-fcc/broadband_api.py
@@ -0,0 +1,15 @@
+from generic_api import *
+
+# Simple Python wrapper around the Broadband API provided by the FCC.
+
+APIS = [("get_data", "http://data.fcc.gov/api/speedtest/find")]
+
+class BroadbandApi(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = BroadbandApi()
+ print bb.get_data(latitude=37, longitude=-122) # (Should be San Francisco)
View
130 build/lib.linux-x86_64-2.6/python-fcc/generic_api.py
@@ -0,0 +1,130 @@
+import urllib
+import json
+
+class NoArgumentsException(Exception):
+ def __str__(self):
+ return "No arguments were found."
+
+class BadJSONException(Exception):
+ def __str__(self):
+ return "The returned JSON was invalid."
+
+class NonexistentStyleException(Exception):
+ def __str__(self):
+ return "The requested API style was invalid."
+
+class MustBeOrderedException(Exception):
+ def __str__(self):
+ return "The arguments you pass to the SBA API must be ordered."
+
+
+# Perform requests to generic APIs.
+
+PHP_STYLE = 0 # &x=1&y=2
+SBA_WEIRD_STYLE = 1
+
+class BaseAPIRequest:
+ def __init__(self, url):
+ self.url = url
+
+ if self.url.startswith("http://api.sba.gov") or self.url.startswith("api.sba.gov"):
+ self.api_style = SBA_WEIRD_STYLE
+ else:
+ self.api_style = PHP_STYLE
+
+ def __format_url_php_style(self, *ordered_args, **args):
+ """
+ Format the url with the arguments in PHP style. That is,
+ ?x=5&y=6
+ """
+ if args is None: raise NoArgumentsException
+
+ args["format"] = "json" #Ask for JSON formatted response
+ append = ""
+
+ for arg in args: append += str(arg) + "=" + str(args[arg]) + "&"
+
+ append = append[:-1] #Take off last '&'
+ self.formatted_url = self.url + "?" + append
+
+ def __format_url_weird_style(self, *ordered_args, **args):
+ """
+ Format the url with the arguments in the weird style given by SBA.
+ arg1/arg2/arg3.json
+ """
+
+ append = ""
+ for arg in ordered_args: append += str(arg) + "/"
+ append = append[:-1] #Take off last '/'
+
+
+ self.formatted_url = self.url + append + ".json"
+
+ # Formats a URL with the provided keyword arguments.
+ def format_url(self, *ordered_args, **args):
+ if self.api_style == PHP_STYLE:
+ self.__format_url_php_style(*ordered_args, **args)
+ elif self.api_style == SBA_WEIRD_STYLE:
+ print ordered_args
+ print args
+ if len(args) != 0:
+ raise MustBeOrderedException # MUST be ordered.
+
+ self.__format_url_weird_style(*ordered_args)
+ else:
+ raise NonexistentStyleException
+
+ # Requests the API and returns the JSON object.
+ def request(self, *ordered_args, **args):
+ self.format_url(*ordered_args, **args)
+ #print self.formatted_url
+ t = urllib.urlopen(self.formatted_url).read().strip()
+ if t.startswith("callback("):
+ t=t[t.index("(")+1:-1]
+
+ print self.formatted_url
+
+ try:
+ return json.loads(t)
+
+ except:
+ raise BadJSONException
+ return None
+
+
+class GenericAPI:
+
+ """
+ __init__
+ Parameters: APIS, a list of tuples of form (FUNCTIONNAME, LINK).
+
+ Creates functions of name FUNCTIONNAME that perform an API call to LINK
+ when called, giving back the response as JSON.
+
+ Returns: Nothing
+ """
+
+ def __init__(self, apis):
+
+ self.api_objects = []
+ self.api_functions = []
+ self.functions = []
+
+ # Who writes normal functions when you can use CLOSURES?!?
+
+ number = 0
+
+ # Bind each function to the class.
+ for api in apis:
+ self.api_objects.append(BaseAPIRequest(api[1]))
+ self.bind_closure(number)
+ setattr(self, api[0], self.api_functions[number])
+ number += 1
+
+ # Creates a function on the current class.
+ def bind_closure(self, number):
+ def generic_api_call(*ordered_args, **kwargs):
+ self.api_objects[number].format_url(*ordered_args, **kwargs)
+ return self.api_objects[number].request(*ordered_args, **kwargs)
+
+ self.api_functions.append(generic_api_call)
View
22 build/lib.linux-x86_64-2.6/python-fcc/license_view_api.py
@@ -0,0 +1,22 @@
+from generic_api import *
+
+# Simple Python wrapper around the License View API provided by the FCC.
+
+APIS = [ ("get_licenses", "http://data.fcc.gov/api/license-view/basicSearch/getLicenses" )
+ , ("get_common_names", "http://data.fcc.gov/api/license-view/licenses/getCommonNames")
+ , ("get_statuses", "http://data.fcc.gov/api/license-view/licenses/getStatuses")
+ , ("get_categories", "http://data.fcc.gov/api/license-view/licenses/getCategories")
+ , ("get_entities", "http://data.fcc.gov/api/license-view/licenses/getEntities")
+ , ("get_renewals", "http://data.fcc.gov/api/license-view/licenses/getRenewals")
+ , ("get_issued", "http://data.fcc.gov/api/license-view/licenses/getIssued")
+ ]
+
+
+class LicenseViewAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+# Sample use of BlockConversionAPI
+if __name__ == "__main__":
+ bc = LicenseViewAPI()
+ print bc.get_licenses(searchValue = "Verizon Wireless")
View
33 build/lib.linux-x86_64-2.6/python-fcc/sba_businesses_api.py
@@ -0,0 +1,33 @@
+from generic_api import *
+
+# Simple Python wrapper around the SBA Business API.
+
+def build_api_list(list, base):
+ result = []
+ for item in list:
+ result.append((item, base + "/" + item + "/" ))
+
+ return result
+
+
+#These are the function calls that the SBABusinessesAPI object exposes.
+list = [ "by_category"
+ , "all_by_state"
+ , "by_business_type"
+ , "state_only"
+ , "state_and_county"
+ , "state_and_city"
+ , "by_zip"
+ ]
+
+APIS = build_api_list(list, "http://api.sba.gov/license_permit")
+
+class SBABusinessesAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = SBABusinessesAPI()
+ print bb.by_category("doing business as") # (Should be San Francisco)
View
35 build/lib.linux-x86_64-2.6/python-fcc/sba_loans_grants_api.py
@@ -0,0 +1,35 @@
+from generic_api import *
+
+# Simple Python wrapper around the SBA Business API.
+
+def build_api_list(list, base):
+ result = []
+ for item in list:
+ result.append((item, base + "/" + item + "/" ))
+
+ return result
+
+
+#These are the function calls that the SBABusinessesAPI object exposes.
+list = [ "federal"
+ , "state_financing_for"
+ , "federal_and_state_financing_for"
+ # , "nil/for_profit"
+ # , "nil/for_profit/nil" #What were they thinking?!
+ # , "nil/for_profit"
+ # STATE ABBREVIATION/for_profit/nil/SPECIALTY
+ # STATE ABBREVIATION/for_profit/nil/SPECIALTY1-SPECIALTY2- ... SPECIALTYN
+ # STATE ABBREVIATION/for_profit/INDUSTRY/SPECIALTY
+ ]
+
+APIS = build_api_list(list, "http://api.sba.gov/loans_grants")
+
+class SBALoansGrantsAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = SBALoansGrantsAPI()
+ print bb.by_category("doing business as") # (Should be San Francisco)
View
0  build/lib.linux-x86_64-2.6/python-fcc/tests/__init__.py
No changes.
View
5 build/lib.linux-x86_64-2.6/python-fcc/tests/__main__.py
@@ -0,0 +1,5 @@
+from tests.testcases import *
+from tests.testutils import *
+
+if __name__ == '__main__':
+ unittest.main()
View
105 build/lib.linux-x86_64-2.6/python-fcc/tests/testcases.py
@@ -0,0 +1,105 @@
+import sys
+import unittest
+
+sys.path.append('../')
+
+from broadband_api import *
+from FRNConversionsAPI import *
+from block_conversion_api import *
+
+class TestBroadbandAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BroadbandApi()
+ self.frnapi = FRNConversionsAPI()
+
+
+ #Sweep across the US and compare to precomputed values.
+ def test_Sweep(self):
+
+ # The following is how I computed the values beforehand:
+
+ # print "results = "
+ # print "[",
+ # for x in range(10):
+ # print self.bb.request(latitude=41, longitude=-86 + x * 10)['status'] == 'OK', ",",
+ # print "]"
+ results = [ True , True , False , False , False , False , False , False , False , False , ]
+
+ for x in range(10):
+ self.assertTrue((self.bb.get_data(latitude=41, longitude=-86 + x * 10)['status'] == 'OK') == results[x])
+
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_data(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue('SpeedTestCounty' in result)
+
+ # Does Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_data(latitude=41, longitude=-87)
+
+ self.assertTrue(result['status'] == 'OK')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_data(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+ def test_FRN(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['frn'] == '0017855545')
+
+ def test_companyName(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['companyName']=='Cygnus Telecommunications Corporation')
+
+ def test_FRNapiIsDict(self):
+ result1 = self.frnapi.getList(stateCode='IL')
+ result2 = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(type(result1)==type({}) and type(result2)==type({}))
+ def test_CygnusInIL(self):
+ result = self.frnapi.getList(stateCode='IL')
+ #print result['Frns']
+ #Cygnus Telecommunications Corporation
+ self.assertTrue('Cygnus Telecommunications Corporation' in [x['companyName'] for x in result['Frns']['Frn']])
+
+
+
+
+
+
+
+class TestBlockConversionAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BlockConversionAPI()
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_block(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue(result['State']['code'] == 'CA')
+ self.assertTrue(result['Block']['FIPS'] == '060871001001002C')
+
+
+ # Does (somewhere near) Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_block(latitude=41, longitude=-87)
+
+ self.assertTrue(result['Block']['FIPS'] == '180739908004112')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_block(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+if __name__ == '__main__':
+ unittest.main()
View
BIN  dist/python_fcc-0.1-py2.6.egg
Binary file not shown
View
45 python-fcc/FRNConversionsAPI.py
@@ -0,0 +1,45 @@
+from generic_api import *
+import urllib,json
+
+
+# Simple Python wrapper around the Broadband API provided by the FCC.
+
+class FRNConversionsAPI(GenericAPI):
+ """
+ FRNConversionsAPI:
+ - an API to access information about broadband provides.
+ - original API: http://reboot.fcc.gov/developer/frn-conversions-api
+
+ - methods:
+ -- getList(stateCode, multi)
+ takes stateCode=IL or stateCode=17 (FIPS code),
+ (optional) multi=Yes or multi=No to signify whether to include FRNs also operating outside this state.
+
+ -- getInfo(frn)
+ takes frn='0017855545' (FRN id)
+ """
+
+
+ def __init__(self):
+ apis= [
+ ('getList', 'http://data.fcc.gov/api/frn/getList'),
+ ('getInfo', 'http://data.fcc.gov/api/frn/getInfo')]
+
+ GenericAPI.__init__(self,apis)
+
+
+if __name__ == "__main__":
+ bb = FRNConversionsAPI()
+
+ x=bb.getList(stateCode='IL')
+ print type(x)
+ print len(x)
+ print x.keys()
+
+ #print x
+
+ print
+ x=bb.getInfo(frn='0017855545')
+ print type(x)
+ print len(x)
+ print x
View
0  python-fcc/__init__.py
No changes.
View
13 python-fcc/block_conversion_api.py
@@ -0,0 +1,13 @@
+from generic_api import *
+
+# Simple Python wrapper around the Block Conversion API provided by the FCC.
+
+class BlockConversionAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, [("get_block", "http://data.fcc.gov/api/block/find")])
+
+
+# Sample use of BlockConversionAPI
+if __name__ == "__main__":
+ bc = BlockConversionAPI()
+ print bc.get_block(lat=41, long=-87) # (Should be San Francisco)
View
15 python-fcc/broadband_api.py
@@ -0,0 +1,15 @@
+from generic_api import *
+
+# Simple Python wrapper around the Broadband API provided by the FCC.
+
+APIS = [("get_data", "http://data.fcc.gov/api/speedtest/find")]
+
+class BroadbandApi(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = BroadbandApi()
+ print bb.get_data(latitude=37, longitude=-122) # (Should be San Francisco)
View
0  python-fcc/build/lib.linux-x86_64-2.6/tests/__init__.py
No changes.
View
5 python-fcc/build/lib.linux-x86_64-2.6/tests/__main__.py
@@ -0,0 +1,5 @@
+from tests.testcases import *
+from tests.testutils import *
+
+if __name__ == '__main__':
+ unittest.main()
View
105 python-fcc/build/lib.linux-x86_64-2.6/tests/testcases.py
@@ -0,0 +1,105 @@
+import sys
+import unittest
+
+sys.path.append('../')
+
+from broadband_api import *
+from FRNConversionsAPI import *
+from block_conversion_api import *
+
+class TestBroadbandAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BroadbandApi()
+ self.frnapi = FRNConversionsAPI()
+
+
+ #Sweep across the US and compare to precomputed values.
+ def test_Sweep(self):
+
+ # The following is how I computed the values beforehand:
+
+ # print "results = "
+ # print "[",
+ # for x in range(10):
+ # print self.bb.request(latitude=41, longitude=-86 + x * 10)['status'] == 'OK', ",",
+ # print "]"
+ results = [ True , True , False , False , False , False , False , False , False , False , ]
+
+ for x in range(10):
+ self.assertTrue((self.bb.get_data(latitude=41, longitude=-86 + x * 10)['status'] == 'OK') == results[x])
+
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_data(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue('SpeedTestCounty' in result)
+
+ # Does Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_data(latitude=41, longitude=-87)
+
+ self.assertTrue(result['status'] == 'OK')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_data(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+ def test_FRN(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['frn'] == '0017855545')
+
+ def test_companyName(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['companyName']=='Cygnus Telecommunications Corporation')
+
+ def test_FRNapiIsDict(self):
+ result1 = self.frnapi.getList(stateCode='IL')
+ result2 = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(type(result1)==type({}) and type(result2)==type({}))
+ def test_CygnusInIL(self):
+ result = self.frnapi.getList(stateCode='IL')
+ #print result['Frns']
+ #Cygnus Telecommunications Corporation
+ self.assertTrue('Cygnus Telecommunications Corporation' in [x['companyName'] for x in result['Frns']['Frn']])
+
+
+
+
+
+
+
+class TestBlockConversionAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BlockConversionAPI()
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_block(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue(result['State']['code'] == 'CA')
+ self.assertTrue(result['Block']['FIPS'] == '060871001001002C')
+
+
+ # Does (somewhere near) Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_block(latitude=41, longitude=-87)
+
+ self.assertTrue(result['Block']['FIPS'] == '180739908004112')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_block(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+if __name__ == '__main__':
+ unittest.main()
View
BIN  python-fcc/dist/python_fcc-0.1-py2.6.egg
Binary file not shown
View
130 python-fcc/generic_api.py
@@ -0,0 +1,130 @@
+import urllib
+import json
+
+class NoArgumentsException(Exception):
+ def __str__(self):
+ return "No arguments were found."
+
+class BadJSONException(Exception):
+ def __str__(self):
+ return "The returned JSON was invalid."
+
+class NonexistentStyleException(Exception):
+ def __str__(self):
+ return "The requested API style was invalid."
+
+class MustBeOrderedException(Exception):
+ def __str__(self):
+ return "The arguments you pass to the SBA API must be ordered."
+
+
+# Perform requests to generic APIs.
+
+PHP_STYLE = 0 # &x=1&y=2
+SBA_WEIRD_STYLE = 1
+
+class BaseAPIRequest:
+ def __init__(self, url):
+ self.url = url
+
+ if self.url.startswith("http://api.sba.gov") or self.url.startswith("api.sba.gov"):
+ self.api_style = SBA_WEIRD_STYLE
+ else:
+ self.api_style = PHP_STYLE
+
+ def __format_url_php_style(self, *ordered_args, **args):
+ """
+ Format the url with the arguments in PHP style. That is,
+ ?x=5&y=6
+ """
+ if args is None: raise NoArgumentsException
+
+ args["format"] = "json" #Ask for JSON formatted response
+ append = ""
+
+ for arg in args: append += str(arg) + "=" + str(args[arg]) + "&"
+
+ append = append[:-1] #Take off last '&'
+ self.formatted_url = self.url + "?" + append
+
+ def __format_url_weird_style(self, *ordered_args, **args):
+ """
+ Format the url with the arguments in the weird style given by SBA.
+ arg1/arg2/arg3.json
+ """
+
+ append = ""
+ for arg in ordered_args: append += str(arg) + "/"
+ append = append[:-1] #Take off last '/'
+
+
+ self.formatted_url = self.url + append + ".json"
+
+ # Formats a URL with the provided keyword arguments.
+ def format_url(self, *ordered_args, **args):
+ if self.api_style == PHP_STYLE:
+ self.__format_url_php_style(*ordered_args, **args)
+ elif self.api_style == SBA_WEIRD_STYLE:
+ print ordered_args
+ print args
+ if len(args) != 0:
+ raise MustBeOrderedException # MUST be ordered.
+
+ self.__format_url_weird_style(*ordered_args)
+ else:
+ raise NonexistentStyleException
+
+ # Requests the API and returns the JSON object.
+ def request(self, *ordered_args, **args):
+ self.format_url(*ordered_args, **args)
+ #print self.formatted_url
+ t = urllib.urlopen(self.formatted_url).read().strip()
+ if t.startswith("callback("):
+ t=t[t.index("(")+1:-1]
+
+ print self.formatted_url
+
+ try:
+ return json.loads(t)
+
+ except:
+ raise BadJSONException
+ return None
+
+
+class GenericAPI:
+
+ """
+ __init__
+ Parameters: APIS, a list of tuples of form (FUNCTIONNAME, LINK).
+
+ Creates functions of name FUNCTIONNAME that perform an API call to LINK
+ when called, giving back the response as JSON.
+
+ Returns: Nothing
+ """
+
+ def __init__(self, apis):
+
+ self.api_objects = []
+ self.api_functions = []
+ self.functions = []
+
+ # Who writes normal functions when you can use CLOSURES?!?
+
+ number = 0
+
+ # Bind each function to the class.
+ for api in apis:
+ self.api_objects.append(BaseAPIRequest(api[1]))
+ self.bind_closure(number)
+ setattr(self, api[0], self.api_functions[number])
+ number += 1
+
+ # Creates a function on the current class.
+ def bind_closure(self, number):
+ def generic_api_call(*ordered_args, **kwargs):
+ self.api_objects[number].format_url(*ordered_args, **kwargs)
+ return self.api_objects[number].request(*ordered_args, **kwargs)
+
+ self.api_functions.append(generic_api_call)
View
22 python-fcc/license_view_api.py
@@ -0,0 +1,22 @@
+from generic_api import *
+
+# Simple Python wrapper around the License View API provided by the FCC.
+
+APIS = [ ("get_licenses", "http://data.fcc.gov/api/license-view/basicSearch/getLicenses" )
+ , ("get_common_names", "http://data.fcc.gov/api/license-view/licenses/getCommonNames")
+ , ("get_statuses", "http://data.fcc.gov/api/license-view/licenses/getStatuses")
+ , ("get_categories", "http://data.fcc.gov/api/license-view/licenses/getCategories")
+ , ("get_entities", "http://data.fcc.gov/api/license-view/licenses/getEntities")
+ , ("get_renewals", "http://data.fcc.gov/api/license-view/licenses/getRenewals")
+ , ("get_issued", "http://data.fcc.gov/api/license-view/licenses/getIssued")
+ ]
+
+
+class LicenseViewAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+# Sample use of BlockConversionAPI
+if __name__ == "__main__":
+ bc = LicenseViewAPI()
+ print bc.get_licenses(searchValue = "Verizon Wireless")
View
10 python-fcc/python_fcc.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: python-fcc
+Version: 0.1
+Summary: An API abstraction of the FCC API found at http://reboot.fcc.gov/developer
+Home-page: http://github.com/codeforamerica/FCC-Python-Egg
+Author: johnfn, quadrismegistus
+Author-email: grantm@stanford.edu, heuser@stanford.edu
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
View
8 python-fcc/python_fcc.egg-info/SOURCES.txt
@@ -0,0 +1,8 @@
+setup.py
+python_fcc.egg-info/PKG-INFO
+python_fcc.egg-info/SOURCES.txt
+python_fcc.egg-info/dependency_links.txt
+python_fcc.egg-info/top_level.txt
+tests/__init__.py
+tests/__main__.py
+tests/testcases.py
View
1  python-fcc/python_fcc.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
View
1  python-fcc/python_fcc.egg-info/top_level.txt
@@ -0,0 +1 @@
+tests
View
33 python-fcc/sba_businesses_api.py
@@ -0,0 +1,33 @@
+from generic_api import *
+
+# Simple Python wrapper around the SBA Business API.
+
+def build_api_list(list, base):
+ result = []
+ for item in list:
+ result.append((item, base + "/" + item + "/" ))
+
+ return result
+
+
+#These are the function calls that the SBABusinessesAPI object exposes.
+list = [ "by_category"
+ , "all_by_state"
+ , "by_business_type"
+ , "state_only"
+ , "state_and_county"
+ , "state_and_city"
+ , "by_zip"
+ ]
+
+APIS = build_api_list(list, "http://api.sba.gov/license_permit")
+
+class SBABusinessesAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = SBABusinessesAPI()
+ print bb.by_category("doing business as") # (Should be San Francisco)
View
35 python-fcc/sba_loans_grants_api.py
@@ -0,0 +1,35 @@
+from generic_api import *
+
+# Simple Python wrapper around the SBA Business API.
+
+def build_api_list(list, base):
+ result = []
+ for item in list:
+ result.append((item, base + "/" + item + "/" ))
+
+ return result
+
+
+#These are the function calls that the SBABusinessesAPI object exposes.
+list = [ "federal"
+ , "state_financing_for"
+ , "federal_and_state_financing_for"
+ # , "nil/for_profit"
+ # , "nil/for_profit/nil" #What were they thinking?!
+ # , "nil/for_profit"
+ # STATE ABBREVIATION/for_profit/nil/SPECIALTY
+ # STATE ABBREVIATION/for_profit/nil/SPECIALTY1-SPECIALTY2- ... SPECIALTYN
+ # STATE ABBREVIATION/for_profit/INDUSTRY/SPECIALTY
+ ]
+
+APIS = build_api_list(list, "http://api.sba.gov/loans_grants")
+
+class SBALoansGrantsAPI(GenericAPI):
+ def __init__(self):
+ GenericAPI.__init__(self, APIS)
+
+
+# Sample use of BroadbandApi
+if __name__ == "__main__":
+ bb = SBALoansGrantsAPI()
+ print bb.by_category("doing business as") # (Should be San Francisco)
View
0  python-fcc/tests/__init__.py
No changes.
View
5 python-fcc/tests/__main__.py
@@ -0,0 +1,5 @@
+from tests.testcases import *
+from tests.testutils import *
+
+if __name__ == '__main__':
+ unittest.main()
View
105 python-fcc/tests/testcases.py
@@ -0,0 +1,105 @@
+import sys
+import unittest
+
+sys.path.append('../')
+
+from broadband_api import *
+from FRNConversionsAPI import *
+from block_conversion_api import *
+
+class TestBroadbandAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BroadbandApi()
+ self.frnapi = FRNConversionsAPI()
+
+
+ #Sweep across the US and compare to precomputed values.
+ def test_Sweep(self):
+
+ # The following is how I computed the values beforehand:
+
+ # print "results = "
+ # print "[",
+ # for x in range(10):
+ # print self.bb.request(latitude=41, longitude=-86 + x * 10)['status'] == 'OK', ",",
+ # print "]"
+ results = [ True , True , False , False , False , False , False , False , False , False , ]
+
+ for x in range(10):
+ self.assertTrue((self.bb.get_data(latitude=41, longitude=-86 + x * 10)['status'] == 'OK') == results[x])
+
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_data(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue('SpeedTestCounty' in result)
+
+ # Does Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_data(latitude=41, longitude=-87)
+
+ self.assertTrue(result['status'] == 'OK')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_data(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+ def test_FRN(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['frn'] == '0017855545')
+
+ def test_companyName(self):
+ result = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(result['Info']['companyName']=='Cygnus Telecommunications Corporation')
+
+ def test_FRNapiIsDict(self):
+ result1 = self.frnapi.getList(stateCode='IL')
+ result2 = self.frnapi.getInfo(frn='0017855545')
+ self.assertTrue(type(result1)==type({}) and type(result2)==type({}))
+ def test_CygnusInIL(self):
+ result = self.frnapi.getList(stateCode='IL')
+ #print result['Frns']
+ #Cygnus Telecommunications Corporation
+ self.assertTrue('Cygnus Telecommunications Corporation' in [x['companyName'] for x in result['Frns']['Frn']])
+
+
+
+
+
+
+
+class TestBlockConversionAPI (unittest.TestCase):
+ def setUp(self):
+ self.bb = BlockConversionAPI()
+
+ # Does SF exist?
+ def test_SF(self):
+ result = self.bb.get_block(latitude=37, longitude=-122)
+
+ self.assertTrue(result['status'] == 'OK')
+ self.assertTrue(result['State']['code'] == 'CA')
+ self.assertTrue(result['Block']['FIPS'] == '060871001001002C')
+
+
+ # Does (somewhere near) Chicago exist?
+ def test_Chicago(self):
+ result = self.bb.get_block(latitude=41, longitude=-87)
+
+ self.assertTrue(result['Block']['FIPS'] == '180739908004112')
+
+
+ # Test the middle of nowhere (Disclaimer: I have no idea where
+ # this is, so it may not be in the middle of nowhere)
+ def test_Nowhere(self):
+ result = self.bb.get_block(latitude=35, longitude=35)
+
+ self.assertTrue(result['status'] == 'Fail')
+
+if __name__ == '__main__':
+ unittest.main()
View
10 python_fcc.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: python-fcc
+Version: 0.1
+Summary: An API abstraction of the FCC API found at http://reboot.fcc.gov/developer
+Home-page: http://github.com/codeforamerica/FCC-Python-Egg
+Author: johnfn, quadrismegistus
+Author-email: grantm@stanford.edu, heuser@stanford.edu
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
View
16 python_fcc.egg-info/SOURCES.txt
@@ -0,0 +1,16 @@
+setup.py
+python-fcc/FRNConversionsAPI.py
+python-fcc/__init__.py
+python-fcc/block_conversion_api.py
+python-fcc/broadband_api.py
+python-fcc/generic_api.py
+python-fcc/license_view_api.py
+python-fcc/sba_businesses_api.py
+python-fcc/sba_loans_grants_api.py
+python-fcc/tests/__init__.py
+python-fcc/tests/__main__.py
+python-fcc/tests/testcases.py
+python_fcc.egg-info/PKG-INFO
+python_fcc.egg-info/SOURCES.txt
+python_fcc.egg-info/dependency_links.txt
+python_fcc.egg-info/top_level.txt
View
1  python_fcc.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
View
1  python_fcc.egg-info/top_level.txt
@@ -0,0 +1 @@
+python-fcc
View
10 setup.py
@@ -0,0 +1,10 @@
+from setuptools import setup, find_packages
+setup(
+ name = "python-fcc",
+ version = "0.1",
+ description = "An API abstraction of the FCC API found at http://reboot.fcc.gov/developer",
+ author='johnfn, quadrismegistus',
+ author_email='grantm@stanford.edu, heuser@stanford.edu',
+ url='http://github.com/codeforamerica/FCC-Python-Egg',
+ packages = find_packages(),
+)

1 comment on commit b8dcf82

@dcolish

Looks like a lot of the dist and build code got committed. Might want to also add package ignores for any tests. Maybe consider a namespace for the top level?

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