Skip to content

Commit

Permalink
detecting already filled self.gis_db
Browse files Browse the repository at this point in the history
  • Loading branch information
wschuell committed Nov 23, 2023
1 parent a2f54b0 commit ab4f601
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions gis_fillers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def clean_db(self, gis_data_stay=False, commit=True, extra_whitelist=[], **kwarg
self, commit=commit, extra_whitelist=extra_whitelist, **kwargs
)

def get_gis_db(self, schema="postgis", replace=False, fill_db=True):
def get_gis_db(self, schema="postgis", replace=False, fill_db=True, force=False):
if not hasattr(self, "gis_db") or replace:
conninfo = copy.deepcopy(self.db_conninfo)
conninfo["db_schema"] = schema
self.gis_db = Database(**conninfo)
self.gis_db.init_db()
if fill_db:
self.gis_db.add_filler(MetaFiller())
self.gis_db.fill_db()
self.gis_db.connection.commit()
self.gis_db.cursor.execute("SELECT 1 FROM geonames_zipcodes LIMIT 1;")
if force or not list(self.gis_db.cursor.fetchall()):
self.gis_db.add_filler(MetaFiller())
self.gis_db.fill_db()
self.gis_db.connection.commit()
return self.gis_db

0 comments on commit ab4f601

Please sign in to comment.