@@ 85-96 (lines=12) @@ | ||
82 | def get_or_create_common(session, model, **kwargs): |
|
83 | if kwargs['poi_code'] is not None and kwargs['poi_code'] != '': |
|
84 | instance = session.query(model).filter_by(poi_code=kwargs['poi_code']).first() |
|
85 | if instance: |
|
86 | logging.debug('Already added: %s', instance) |
|
87 | return instance |
|
88 | else: |
|
89 | try: |
|
90 | instance = model(**kwargs) |
|
91 | session.add(instance) |
|
92 | return instance |
|
93 | except Exception as e: |
|
94 | logging.error('Cannot add to the database. (%s)', e) |
|
95 | logging.exception('Exception occurred') |
|
96 | raise e |
|
97 | ||
98 | def insert_city_dataframe(session, city_df): |
|
99 | city_df.columns = ['city_post_code', 'city_name'] |
|
@@ 69-80 (lines=12) @@ | ||
66 | if kwargs.get('osm_id') is not None and kwargs.get('osm_object_type'): |
|
67 | instance = session.query(model) \ |
|
68 | .filter_by(osm_id=kwargs.get('osm_id')).filter_by(osm_object_type=kwargs.get('poi_addr_city')).first() |
|
69 | if instance: |
|
70 | logging.debug('Already added: %s', instance) |
|
71 | return instance |
|
72 | else: |
|
73 | try: |
|
74 | instance = model(**kwargs) |
|
75 | session.add(instance) |
|
76 | return instance |
|
77 | except Exception as e: |
|
78 | logging.error('Cannot add to the database. (%s)', e) |
|
79 | logging.exception('Exception occurred') |
|
80 | raise e |
|
81 | ||
82 | def get_or_create_common(session, model, **kwargs): |
|
83 | if kwargs['poi_code'] is not None and kwargs['poi_code'] != '': |
|
@@ 51-62 (lines=12) @@ | ||
48 | .filter_by(poi_conscriptionnumber=kwargs['poi_conscriptionnumber']) \ |
|
49 | .filter_by(poi_branch=kwargs['poi_branch']) \ |
|
50 | .first() |
|
51 | if instance: |
|
52 | logging.debug('Already added: %s', instance) |
|
53 | return instance |
|
54 | else: |
|
55 | try: |
|
56 | instance = model(**kwargs) |
|
57 | session.add(instance) |
|
58 | return instance |
|
59 | except Exception as e: |
|
60 | logging.error('Cannot add to the database. (%s)', e) |
|
61 | logging.exception('Exception occurred') |
|
62 | raise e |
|
63 | ||
64 | ||
65 | def get_or_create_cache(session, model, **kwargs): |
|
@@ 21-32 (lines=12) @@ | ||
18 | ||
19 | def get_or_create(session, model, **kwargs): |
|
20 | instance = session.query(model).filter_by(**kwargs).first() |
|
21 | if instance: |
|
22 | logging.debug('Already added: %s', instance) |
|
23 | return instance |
|
24 | else: |
|
25 | try: |
|
26 | instance = model(**kwargs) |
|
27 | session.add(instance) |
|
28 | return instance |
|
29 | except Exception as e: |
|
30 | logging.error('Cannot add to the database. (%s)', e) |
|
31 | logging.exception('Exception occurred') |
|
32 | raise e |
|
33 | ||
34 | ||
35 | def get_or_create_poi(session, model, **kwargs): |