Skip to content
Snippets Groups Projects
Commit e770c5ba authored by Alessandro Cerioni's avatar Alessandro Cerioni
Browse files

Making code robust w/ respect to non-existing tables.

parent 0759c0ef
No related branches found
No related tags found
No related merge requests found
...@@ -8,26 +8,24 @@ from utils.exit_gracefully import exit_gracefully ...@@ -8,26 +8,24 @@ from utils.exit_gracefully import exit_gracefully
from utils.my_logging import logging from utils.my_logging import logging
from utils.postgis_helper import Remote from utils.postgis_helper import Remote
from utils.serializers import encode_datetime from utils.serializers import encode_datetime
from sqlalchemy.exc import NoSuchTableError
def get_entries_from_postgis( link, cfg, no_features_per_page=1000 ): def get_entries_from_postgis( link, cfg, no_features_per_page=1000 ):
#print('here', link)
dbname = link['url'].split('/')[-1] dbname = link['url'].split('/')[-1]
schema, table = link['name'].split('.') schema, table_name = link['name'].split('.')
print(dbname, schema, table)
#print(cfg)
#exit(1)
logging.info('Getting data from database %s...' % dbname) logging.info('Getting data from database %s...' % dbname)
logging.info('Establishing a database connection...') logging.info('Establishing a database connection...')
pg = Remote(hostname=cfg['host'], dbname=dbname, username=cfg['username'], password=cfg['password']) pg = Remote(hostname=cfg['host'], dbname=dbname, username=cfg['username'], password=cfg['password'])
logging.info('Done.') logging.info('Done.')
table = pg.get_table(table, schema=schema) try:
table = pg.get_table(table_name, schema=schema)
except NoSuchTableError:
#print(pg.get_tables('bruit')) logging.debug('Table %s in schema % s not found :-(' % (table_name, schema))
return
count = pg.count_entries(table) count = pg.count_entries(table)
...@@ -313,6 +311,7 @@ if __name__ == '__main__': ...@@ -313,6 +311,7 @@ if __name__ == '__main__':
with open("config.yaml", 'r') as yamlfile: with open("config.yaml", 'r') as yamlfile:
cfg = yaml.load(yamlfile) cfg = yaml.load(yamlfile)
main(cfg)
while True: while True:
try: try:
main(cfg) main(cfg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment