Ejemplo n.º 1
0
def main():
	config.parse_options()
	global_vars.storage_handle = storage.connect(global_vars.db_filename)
	model_list = generate_model_list()
	clear_tables(model_list)
	create_new_tables(model_list)
	storage.close(global_vars.storage_handle)
Ejemplo n.º 2
0
	def tearDown(self):
		storage.close(global_vars.storage_handle)
Ejemplo n.º 3
0
def close_connection(exception):
    storage.close()
#!/usr/bin/python
""" Actual distance calculations, can be executed manually, via cron, Jenkins etc. """

import storage, sys, time, distance_matrix
from requests import exceptions

if len(sys.argv) > 1 and sys.argv[1] == 'fresh-start':
    print "Preparing for updated stores."
    storage.clean()
    storage.fill()
    storage.count()
    storage.close()
else:
    print "Getting distances for a bunch of addresses."
    storage.count()

    for x in xrange(700):
        origin = storage.get_next_origin()
        origin_id, origin_lat, origin_lon = origin[0]

        if origin_lat == '' or origin_lon == '':
            storage.add_closest((origin_id, 0, 0, '', 0, ''))
            continue

        destinations = storage.get_addresses_near(origin_id)
        print "Getting pharmacies closest to #%d. There're %d pharmacies near." % (
            origin_id, len(destinations))

        if len(destinations) == 0:
            storage.add_closest((origin_id, 0, 0, '', 0, ''))
            continue