1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
import logging |
5
|
|
|
import sys |
6
|
|
|
import json |
7
|
|
|
from osm_poi_matchmaker.dao.data_handlers import insert_poi_dataframe |
8
|
|
|
from osm_poi_matchmaker.libs.address import extract_all_address, clean_phone_to_str |
9
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
10
|
|
|
from osm_poi_matchmaker.libs.poi_dataset import POIDataset |
11
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
12
|
|
|
from osm_poi_matchmaker.utils.enums import FileType |
13
|
|
|
except ImportError as err: |
14
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
15
|
|
|
logging.exception('Exception occurred') |
16
|
|
|
|
17
|
|
|
sys.exit(128) |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class hu_kh_bank(DataProvider): |
|
|
|
|
21
|
|
|
|
22
|
|
View Code Duplication |
def __init__(self, session, download_cache, prefer_osm_postcode, link, name): |
|
|
|
|
23
|
|
|
self.session = session |
24
|
|
|
self.download_cache = download_cache |
25
|
|
|
self.link = link |
26
|
|
|
self.tags = {'brand': 'K&H', 'operator': 'K&H Bank Zrt.', |
27
|
|
|
'operator:addr': '1095 Budapest, Lechner Ödön fasor 9.', 'bic': 'OKHBHUHB', |
28
|
|
|
'ref:vatin': 'HU10195664', 'ref:vatin:hu': '10195664-4-44', 'ref:HU:company': '01 10 041043', } |
|
|
|
|
29
|
|
|
self.prefer_osm_postcode = prefer_osm_postcode |
30
|
|
|
self.name = name |
31
|
|
|
self.filetype = FileType.json |
32
|
|
|
self.filename = '{}.{}'.format( |
33
|
|
|
self.__class__.__name__, self.filetype.name) |
34
|
|
|
|
35
|
|
|
def types(self): |
36
|
|
|
hukhbank = {'amenity': 'bank', 'atm': 'yes', |
37
|
|
|
'air_conditioning': 'yes', } |
38
|
|
|
hukhbank.update(self.tags) |
39
|
|
|
hukhatm = {'amenity': 'atm'} |
40
|
|
|
hukhatm.update(self.tags) |
41
|
|
|
self.__types = [ |
42
|
|
|
{'poi_code': 'hukhbank', 'poi_name': 'K&H Bank', 'poi_type': 'bank', |
43
|
|
|
'poi_tags': hukhbank, 'poi_url_base': 'https://www.kh.hu', |
44
|
|
|
'poi_search_name': '(kh bank|k&h bank|k&h|kh)', 'osm_search_distance_perfect': 2000, |
45
|
|
|
'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 4}, |
46
|
|
|
{'poi_code': 'hukhatm', 'poi_name': 'K&H Bank ATM', 'poi_type': 'atm', |
47
|
|
|
'poi_tags': hukhatm, 'poi_url_base': 'https://www.kh.hu', |
48
|
|
|
'poi_search_name': '(kh bank atm|k&h bank atm|k&h atm|kh atm)', |
49
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 80, |
50
|
|
|
'osm_search_distance_unsafe': 3}, |
51
|
|
|
] |
52
|
|
|
return self.__types |
53
|
|
|
|
54
|
|
|
def process(self): |
55
|
|
|
try: |
56
|
|
|
if self.link: |
57
|
|
|
with open(self.link, 'r') as f: |
|
|
|
|
58
|
|
|
text = json.load(f) |
59
|
|
|
data = POIDataset() |
60
|
|
|
for poi_data in text['results']: |
61
|
|
|
first_element = next(iter(poi_data)) |
62
|
|
|
if self.name == 'K&H Bank': |
63
|
|
|
data.name = 'K&H Bank' |
64
|
|
|
data.code = 'hukhbank' |
65
|
|
|
data.public_holiday_open = False |
66
|
|
|
elif self.name == 'K&H Bank ATM': |
67
|
|
|
data.name = 'K&H Bank ATM' |
68
|
|
|
data.code = 'hukhatm' |
69
|
|
|
data.public_holiday_open = True |
70
|
|
|
if data.code == 'hukhatm': |
71
|
|
|
data.nonstop = True |
72
|
|
|
else: |
73
|
|
|
data.nonstop = False |
74
|
|
|
data.lat, data.lon = check_hu_boundary(poi_data.get(first_element)['latitude'], |
|
|
|
|
75
|
|
|
poi_data.get(first_element)['longitude']) |
|
|
|
|
76
|
|
|
if poi_data.get(first_element)['address'] is not None and \ |
77
|
|
|
poi_data.get(first_element)['address'] != '': |
78
|
|
|
data.postcode, data.city, data.street, data.housenumber, data.conscriptionnumber = \ |
|
|
|
|
79
|
|
|
extract_all_address( |
80
|
|
|
poi_data.get(first_element)['address']) |
81
|
|
|
data.original = poi_data.get( |
82
|
|
|
first_element)['address'] |
83
|
|
|
if poi_data.get('phoneNumber') is not None and poi_data.get('phoneNumber') != '': |
|
|
|
|
84
|
|
|
data.phone = clean_phone_to_str( |
85
|
|
|
poi_data.get('phoneNumber')) |
86
|
|
|
else: |
87
|
|
|
data.phone = None |
88
|
|
|
data.add() |
89
|
|
|
if data is None or data.lenght() < 1: |
90
|
|
|
logging.warning('Resultset is empty. Skipping ...') |
91
|
|
|
else: |
92
|
|
|
insert_poi_dataframe(self.session, data.process()) |
93
|
|
|
except Exception as e: |
|
|
|
|
94
|
|
|
logging.exception('Exception occurred') |
95
|
|
|
|
96
|
|
|
logging.error(e) |
97
|
|
|
logging.error(poi_data) |
|
|
|
|
98
|
|
|
|