1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
import logging |
5
|
|
|
import sys |
6
|
|
|
import os |
7
|
|
|
import json |
8
|
|
|
from osm_poi_matchmaker.dao.data_handlers import insert_poi_dataframe |
|
|
|
|
9
|
|
|
from osm_poi_matchmaker.libs.soup import save_downloaded_soup |
10
|
|
|
from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city, clean_phone_to_str, \ |
|
|
|
|
11
|
|
|
PATTERN_FULL_URL |
12
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
13
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH |
14
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
15
|
|
|
from osm_poi_matchmaker.utils.enums import FileType |
16
|
|
|
except ImportError as err: |
17
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
18
|
|
|
logging.exception('Exception occurred') |
19
|
|
|
|
20
|
|
|
sys.exit(128) |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class hu_benu(DataProvider): |
|
|
|
|
24
|
|
|
|
25
|
|
View Code Duplication |
def constains(self): |
|
|
|
|
26
|
|
|
self.link = 'https://benu.hu/wordpress-core/wp-admin/admin-ajax.php?action=asl_load_stores&nonce=1900018ba1&load_all=1&layout=1' |
|
|
|
|
27
|
|
|
self.tags = {'brand': 'Benu gyógyszertár', 'dispensing': 'yes', |
28
|
|
|
'contact:facebook': 'https://www.facebook.com/BENUgyogyszertar', |
29
|
|
|
'contact:youtube': 'https://www.youtube.com/channel/UCBLjL10QMtRHdkak0h9exqg', |
30
|
|
|
'air_conditioning': 'yes', } |
31
|
|
|
self.tags.update(POS_HU_GEN) |
32
|
|
|
self.tags.update(PAY_CASH) |
33
|
|
|
self.filetype = FileType.json |
34
|
|
|
self.filename = '{}.{}'.format( |
35
|
|
|
self.__class__.__name__, self.filetype.name) |
36
|
|
|
|
37
|
|
|
def types(self): |
38
|
|
|
hubenupha = {'amenity': 'pharmacy'} |
39
|
|
|
hubenupha.update(self.tags) |
40
|
|
|
self.__types = [ |
41
|
|
|
{'poi_code': 'hubenupha', 'poi_name': 'Benu gyógyszertár', 'poi_type': 'pharmacy', |
42
|
|
|
'poi_tags': hubenupha, 'poi_url_base': 'https://benu.hu', |
43
|
|
|
'poi_search_name': '(benu gyogyszertár|benu)', |
44
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, |
45
|
|
|
'osm_search_distance_unsafe': 20, 'preserve_original_name': True}, |
46
|
|
|
] |
47
|
|
|
return self.__types |
48
|
|
|
|
49
|
|
|
def process(self): |
50
|
|
|
try: |
51
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
52
|
|
|
self.filetype) |
53
|
|
|
if soup is not None: |
54
|
|
|
text = json.loads(str(soup)) |
55
|
|
|
for poi_data in text: |
56
|
|
|
try: |
57
|
|
|
if 'BENU Gyógyszertár' not in poi_data.get('title'): |
58
|
|
|
self.data.name = poi_data.get('title').strip() |
59
|
|
|
self.data.branch = None |
60
|
|
|
else: |
61
|
|
|
self.data.name = 'Benu gyógyszertár' |
62
|
|
|
self.data.branch = poi_data.get('title').strip() |
63
|
|
|
self.data.code = 'hubenupha' |
64
|
|
|
if poi_data.get('description') is not None: |
65
|
|
|
pu_match = PATTERN_FULL_URL.match(poi_data.get('description')) |
66
|
|
|
self.data.website = pu_match.group(0).strip() if pu_match is not None else None |
|
|
|
|
67
|
|
|
else: |
68
|
|
|
self.data.website = None |
69
|
|
|
self.data.city = clean_city(poi_data.get('city')) |
70
|
|
|
self.data.postcode = poi_data.get('postal_code').strip() |
71
|
|
|
self.data.lat, self.data.lon = check_hu_boundary(poi_data.get('lat'), poi_data.get('lng')) |
|
|
|
|
72
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = extract_street_housenumber_better_2( |
|
|
|
|
73
|
|
|
poi_data.get(('street'))) |
74
|
|
|
self.data.original = poi_data.get('street') |
75
|
|
|
if 'phone' in poi_data and poi_data.get('phone') != '': |
76
|
|
|
self.data.phone = clean_phone_to_str( |
77
|
|
|
poi_data.get('phone')) |
78
|
|
|
else: |
79
|
|
|
self.data.phone = None |
80
|
|
|
self.data.public_holiday_open = False |
81
|
|
|
self.data.add() |
82
|
|
|
except Exception as e: |
|
|
|
|
83
|
|
|
logging.error(e) |
84
|
|
|
logging.error(poi_data) |
85
|
|
|
logging.exception('Exception occurred') |
86
|
|
|
|
87
|
|
|
except Exception as e: |
|
|
|
|
88
|
|
|
logging.error(e) |
89
|
|
|
logging.exception('Exception occurred') |
90
|
|
|
|