Commits

razzmataz committed 1b23d3e

generalized from the version that was used to upload npa info

Comments (0)

Files changed (1)

utils/couch-scripts/csv2couch.py

 import os
 import couchdb
 from uuid import uuid4
+from optparse import OptionParser
 
-csv_filename = sys.argv[1]
-couchdb_host = sys.argv[2]
-couchdb_name = sys.argv[3]
+
+parser = OptionParser()
+parser.add_option("-d", "--database", dest="database", 
+                  help="DATABASE database name", metavar="DATABASE")
+parser.add_option("-u", "--url", dest="url",
+                  help="URL url path", metavar="URL")
+parser.add_option("-t", "--record-type", dest="rectype",
+                  help="RECORDTYPE the record type", metavar="RECORDTYPE")
+
+(options, args) = parser.parse_args()
+
+if options.rectype == None:
+    parser.error("must specify the record type")
+if options.database == None:
+    parser.error("must specify the database name")
+if options.url == None:
+    parser.error("must specify the url to the database")
+
+if len(args) == 0:
+    parser.error("must specify a csv file to upload")
+
+#csv_filename = sys.argv[1]
+csv_filename = args[0]
+couchdb_host = options.url
+couchdb_name = options.database
+record_type = options.rectype
 
 csv_data = csv.reader(open(csv_filename))
 headerLine = [ ]
         for col in range(0,len(headerLine)):
             if len(row[col]) > 0:
                 new_dict[headerLine[col]] = row[col]
-        new_dict['type'] = 'area_code'
+        #new_dict['type'] = 'area_code'
+        new_dict['type'] = record_type
         listOfDicts.append(new_dict)
 
 print len(listOfDicts)