| @@ 50-61 (lines=12) @@ | ||
| 47 | .filter_by(poi_conscriptionnumber=kwargs['poi_conscriptionnumber'])\ |
|
| 48 | .filter_by(poi_branch=kwargs['poi_branch'])\ |
|
| 49 | .first() |
|
| 50 | if instance: |
|
| 51 | logging.debug('Already added: %s', instance) |
|
| 52 | return instance |
|
| 53 | else: |
|
| 54 | try: |
|
| 55 | instance = model(**kwargs) |
|
| 56 | session.add(instance) |
|
| 57 | return instance |
|
| 58 | except Exception as e: |
|
| 59 | logging.error('Cannot add to the database. (%s)', e) |
|
| 60 | logging.exception("Exception occurred") |
|
| 61 | raise (e) |
|
| 62 | ||
| 63 | ||
| 64 | def insert_city_dataframe(session, city_df): |
|
| @@ 20-31 (lines=12) @@ | ||
| 17 | ||
| 18 | def get_or_create(session, model, **kwargs): |
|
| 19 | instance = session.query(model).filter_by(**kwargs).first() |
|
| 20 | if instance: |
|
| 21 | logging.debug('Already added: %s' ,instance) |
|
| 22 | return instance |
|
| 23 | else: |
|
| 24 | try: |
|
| 25 | instance = model(**kwargs) |
|
| 26 | session.add(instance) |
|
| 27 | return instance |
|
| 28 | except Exception as e: |
|
| 29 | logging.error('Cannot add to the database. (%s)', e) |
|
| 30 | logging.exception("Exception occurred") |
|
| 31 | raise (e) |
|
| 32 | ||
| 33 | ||
| 34 | def get_or_create_poi(session, model, **kwargs): |
|