]> jfr.im git - irc/rizon/acid.git/blobdiff - pyva/populate-zipcodes.py
Add example for reflection based argument parser
[irc/rizon/acid.git] / pyva / populate-zipcodes.py
index e5c2c2fe202fe20ea5373508c6e406956e416bce..f598d2fa80f134c814e1031bdb29935636e2ddcd 100755 (executable)
@@ -4,16 +4,15 @@
 
 import os
 import sys
-import codecs
-import ConfigParser
+import yaml
 import MySQLdb as db
 
 # find config file and zipcode csv file
-config_filename = 'config.ini'
+config_filename = 'pypsd.yml'
 if not os.path.exists(config_filename):
     config_filename = os.path.join('..', config_filename)
     if not os.path.exists(config_filename):
-        print "We cannot locate the pypsd/pyva config.ini file"
+        print "We cannot locate the configuration file pypsd.yml"
         print 'This script should be run from the root acid/ directory'
         exit(1)
 
@@ -32,15 +31,15 @@ drop_table = '--drop' in sys.argv
 debug = '--debug' in sys.argv
 
 # config
-config = ConfigParser.ConfigParser()
-config.readfp(codecs.open(config_filename, 'r', 'utf8'))
+with open(config_filename, "r") as config_fd:
+    config = yaml.load(config_fd)
 
 # make db pointer
 dbx = db.connect(
-    host=config.get('database''host'),
-    user=config.get('database''user'),
-    passwd=config.get('database''passwd'),
-    db=config.get('database''db'),
+    host=config.get('database').get('host'),
+    user=config.get('database').get('user'),
+    passwd=config.get('database').get('passwd'),
+    db=config.get('database').get('db'),
 )
 dbx.autocommit(True)  # no need to have transactions
 dbp = dbx.cursor()