]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/Census.py
Modified the Data module and download script to download the Summary File 1 data.
[dead/census-tools.git] / src / Census.py
index da9283d2efb20c4c7d1f8896b120fad8f98b3815..0f8d23473144d38602e3094797de3f44cd9b05fb 100644 (file)
@@ -1,5 +1,6 @@
 import pgdb
 
+import Configuration.Defaults
 import GPS
 import SummaryFile1
 
@@ -11,11 +12,16 @@ class Database:
     one or two methods from within this class.
     """
 
-    def __init__(self, _host, _database, _username, _srid):
-        self.connection = pgdb.connect(host=_host,
-                                       database=_database,
-                                       user=_username)
-        self.srid = _srid
+    def __init__(self,
+                 initial_host=Configuration.Defaults.DATABASE_HOST,
+                 initial_database=Configuration.Defaults.DATABASE_NAME,
+                 initial_username=Configuration.Defaults.DATABASE_USERNAME,
+                 initial_srid=Configuration.Defaults.SRID):
+        
+        self.connection = pgdb.connect(host=initial_host,
+                                       database=initial_database,
+                                       user=initial_username)
+        self.srid = initial_srid
 
 
     def __del__(self):
@@ -40,11 +46,12 @@ class Database:
         cursor.execute(query, sql_params)        
         rows = cursor.fetchall()
         cursor.close()
-        
-        if len(rows) > 0:
+
+        # SQL queries that return no results get returned as [[None]].
+        if rows[0][0] != None:
             return rows[0][0]
         else:
-            return None
+            return 0
 
 
     def find_contained_population(self, well_known_text):
@@ -106,10 +113,11 @@ class Database:
         rows = cursor.fetchall()
         cursor.close()
 
-        if (len(rows) > 0):
+        # SQL queries that return no results get returned as [[None]].
+        if rows[0][0] != None:
             return rows[0][0]
         else:
-            return None
+            return 0
 
 
 
@@ -131,8 +139,7 @@ class Database:
         rows = cursor.fetchall()
         cursor.close()
 
-        if len(rows) > 0:
-            return rows[0][0]
-        else:
-            return None
+        # Just pass on the None if that's what we got from the
+        # database.
+        return rows[0][0]