Permalink
Browse files

* Made a --refreshdb option available (i.e. drops existing db and rep…

…laces data with new file info)

* Updated street parser since file configuration changed
* Removed old, no-longer-applicable import statements
* Changed db import script to fallback to certain config file information when data isn't available
  • Loading branch information...
1 parent 81020b3 commit fcb686518101096cc0eb3c600a0718dda8a3a4b9 Jared committed Apr 15, 2012
Showing with 21 additions and 14 deletions.
  1. +2 −3 py/db/setupdb.py
  2. +2 −0 py/street_parser.pl
  3. +17 −11 py/vip_feed_sqlite.py
View
@@ -7,7 +7,6 @@
import xml.etree.cElementTree as ET
from csv import DictReader, QUOTE_MINIMAL, Error as CSVError
from datetime import datetime, tzinfo
-from utils import get_files
from xml.sax.saxutils import escape,unescape
def setupdb(filepath, config):
@@ -423,7 +422,7 @@ def load_data(cursor, config):
line.get('LOCATION_NAME'),
line.get('LINE1'),
line.get('CITY'),
- line.get('STATE'),
+ line.get('STATE', config.get('Main', 'state_abbreviation')),
line.get('ZIP'),
)
)
@@ -586,4 +585,4 @@ def dyn_class(modname,classname):
"""Returns a class of classname from module modname."""
module = __import__(modname)
klass = getattr(module,classname)
- return klass
+ return klass
View
@@ -208,6 +208,8 @@ sub parse_csv_args {
# ...which doesn't help in this case
}
+ $csv_line->{'precinct_id'} = sprintf("%03d", $csv_line->{'precinct_id'});
+
if(!exists $precincts->{$localities->{$csv_line->{'house_district'}} . $csv_line->{'precinct_id'}}) {
$precincts->{$localities->{$csv_line->{'house_district'}} . $csv_line->{'precinct_id'}} = {
name => "House District " . $csv_line->{'house_district'} . " Precinct " . $csv_line->{'precinct_id'},
View
@@ -9,7 +9,6 @@
from datetime import datetime, tzinfo
from optparse import OptionParser,make_option
from ConfigParser import SafeConfigParser
-from utils import get_files
from xml.sax.saxutils import escape,unescape
def main():
@@ -31,7 +30,10 @@ def main():
sys.exit("Please specify a valid config file")
database = "{0}vip_data.db".format(config.get('DataSource','db_dir'))
- setupdb(database, config)
+
+ if opts.refreshdb:
+ setupdb(database, config)
+
datastore = Datastore(database)
cursor = datastore.connect()
@@ -547,14 +549,14 @@ def create_polling_locations(w, cursor, config):
city,
? AS state,
zip
- FROM Polling_Location
- WHERE
- line1 IS NOT NULL AND
- line1!=?""",
+ FROM Polling_Location""",
+# WHERE
+# line1 IS NOT NULL AND
+# line1!=?""",
(
config.get('Polling_Location','polling_prefix'),
config.get('Main', 'state_abbreviation'),
- '',
+# '',
)
)
# cursor.execute("""SELECT
@@ -587,9 +589,9 @@ def create_polling_locations(w, cursor, config):
address = ET.SubElement(root,"address")
- if row['location_name'] is not None:
- location_name = ET.SubElement(address,"location_name")
- location_name.text = escape(row['location_name'])
+
+ location_name = ET.SubElement(address,"location_name")
+ location_name.text = escape(row['location_name'] or "")
line1 = ET.SubElement(address,"line1")
line1.text = escape(row['line1'])
@@ -622,9 +624,13 @@ def create_options_list():
dest="config", default="config.ini",
help="Specifies a config file",
metavar="CONFIG_FILE"),
+
+ make_option("--refreshdb", dest="refreshdb",
+ default=False, action="store_true",
+ help="Forces a database refresh"),
]
return option_list
if __name__ == "__main__":
- main()
+ main()

0 comments on commit fcb6865

Please sign in to comment.