Commits

David Mazary  committed e3e2cce

Changed google_geocoding.py to use pycurl.
This fails in django since pycurl installs a signal handler outside of the main thread.

  • Participants
  • Parent commits f90637b
  • Branches curl

Comments (0)

Files changed (3)

File geolocator/google_geocoding.py

 import urllib
-import urllib2
+import curl
 import StringIO
-import gzip
 import json
 
 ZERO_RESULTS = 'ZERO_RESULTS'
 OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'
 REQUEST_DENIED = 'REQUEST_DENIED'
-INVALID_REQUEST = 'INVALID_REQUEST'  
+INVALID_REQUEST = 'INVALID_REQUEST'
+c = pycurl.Curl()
 
-def get_location(address):
-    address = urllib.quote_plus(address)
-    sensor = 'false'
-    request_str = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=%s' % (address, sensor)
-    request = urllib2.Request(request_str)
-    request.add_header('Accept-Encoding', 'gzip')
-    response = urllib2.urlopen(request)
-    compressed = response.info().getheader('Content-Encoding') == 'gzip'
-    jsonString = response.read()
-    if compressed:
-        compressed_stream = StringIO.StringIO(json)
-        gzip_stream = gzip.GzipFile(fileobj = compressed_stream)
-        jsonString = gzip_stream.read()
+try:
+    import signal
+    signal.signal(signal.SIGPIPE, signal.SIG_IGN)
+except ImportError:
+    pass
+
+## Callback function invoked when body data is ready
+def json_parser(jsonString):
     jsonData = json.loads(jsonString)
     status = jsonData['status']
     if status == ZERO_RESULTS:
             return (addr, lat, lng)
     else:
         return None
+
+def get_location(address):
+    address = urllib.quote_plus(address)
+    request_str = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false' % (address)
+    c.setopt(c.URL, request_str)
+    c.setopt(c.FOLLOWLOCATION, 1)
+    b = StringIO.StringIO()
+    c.setopt(c.WRITEFUNCTION, b.write)
+    c.perform()
+    return json_parser(b.getvalue())

File geolocator/ldap_reader.py

 class Ldap_Reader:
     url = 'ldap://directory.vt.edu'
     basedn = 'ou=People,dc=vt,dc=edu'
-    page_size = 50
+    page_size = 100
 
     def __init__(self, search_key, search_value):
         self.con = ldap.initialize(self.__class__.url)

File resources/database/hokiefinderdb.sqlite3

Binary file modified.