Example #1
0
   if options.append and options.reset:
      parser.error("The append and add data modes are mutually exclusive !")
      parser.print_help()
      sys.exit()

   if not options.fro:
      parser.error("You must specify the table and field source !")
      parser.print_help()
      sys.exit()

   if not options.source_db:
      parser.error("You must specify the source database !")
      parser.print_help()
      sys.exit()

   sengine, sfactory = db.create_factories(options.source_db)
   source_session = sfactory()
   dengine, dfactory = db.create_factories(options.dest_db)
   dest_session = dfactory()
   stablename = options.fro.split(".")

   smeta = MetaData(bind=sengine)
   stable = Table(stablename[0], smeta, autoload=True)

   if options.reset:
      db.reset_database(dengine)

   for record in source_session.query(stable):
      address = getattr(record, stablename[1])
      new_rec = db.AddressGeolocation(address)
      dest_session.add(new_rec)
Example #2
0
                     help="Host to start server (default is 'localhost').",
                     metavar="HOST", default="localhost")
   parser.add_option("-p", "--port", dest="port",
                     help="Port to listen (default is '6666').",
                     metavar="PORT", default="6666")
   parser.add_option("-m", "--map", dest="map",
                     help="Use the Google Maps server mode (the default).",
                     default=True, action="store_true")
   parser.add_option("-e", "--earth", dest="earth",
                     help="Use the Google Earth server mode.",
                     default=False, action="store_true")

   (options, args) = parser.parse_args()

   print "Loading database..."
   ENGINE, SESSION_FACTORY = db.create_factories(options.dbfile)
   print "Starting server...\n"

   GeoHandler = GeoEarthHandler if options.earth else GeoMapHandler
   httpd = BaseHTTPServer.HTTPServer((options.host, int(options.port)), GeoHandler)

   print time.asctime(), "Server Starts - %s:%s" % (options.host, options.port)

   while True:
      try:
         httpd.handle_request()
      except KeyboardInterrupt:
         break

   print
   httpd.server_close()
Example #3
0
if __name__ == "__main__":
   parser = OptionParser(usage=SUPPRESS_USAGE)
   print "Geocoding Service v.%s\nBy %s\n" % (pygeoclients.__version__, pygeoclients.__author__)
   parser.add_option("-f", "--file", dest="dbfile",
                  help="Database to read (default is 'sqlite:///db.db').",
                  metavar="FILENAME", default="sqlite:///db.db")
   parser.add_option("-i", "--interval", dest="interval",
                  help="Interval (in seconds) between calls of Google service (default is '2.0' seconds).",
                  metavar="INTERVAL", default="2.0")
   parser.add_option("-r", "--reprocess", dest="reprocess", action="store_true",
                  help="Force the processing of all records.", default=False)

   (options, args) = parser.parse_args()
   print "Loading database..."
   engine, session_factory = db.create_factories(options.dbfile)
   session = session_factory()

   for row in session.query(db.AddressGeolocation).filter(db.AddressGeolocation.accuracy == None):
      print "Geocoding the address [%s]..." % row.address
      time.sleep(float(options.interval))
      geo_data = geocode(row.address)
      if geo_data["code"] != "200":
         print "\tError: [%s]." % GEOCODE_CODES[geo_data["code"]]
         row.accuracy = -1
         session.add(row)
      else:
         print "\tAccuracy: %s." % GEOCODE_ACCURACY[geo_data["accuracy"]]
         row.lat = geo_data["lat"]
         row.lng = geo_data["lng"]
         row.accuracy = geo_data["accuracy"]