1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
import logging |
5
|
|
|
import sys |
6
|
|
|
import os |
7
|
|
|
import json |
8
|
|
|
from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city |
9
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
10
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH |
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_kulcs_patika(DataProvider): |
|
|
|
|
21
|
|
|
|
22
|
|
|
def constains(self): |
23
|
|
|
self.link = 'https://kulcspatikak.hu/gykeress_feed.php' |
24
|
|
|
self.tags = {'amenity': 'pharmacy', 'brand': 'Kulcs Patika', |
25
|
|
|
'dispensing': 'yes', 'air_conditioning': 'yes'} |
26
|
|
|
self.headers = {'Referer': 'https://kulcspatikak.hu/patikakereso', |
27
|
|
|
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0', |
|
|
|
|
28
|
|
|
'Accept': 'application/json, text/javascript, */*; q=0.01'} |
29
|
|
|
self.post = {'megyeid': -1, 'quality_check': 0, |
30
|
|
|
'animal_check': 0, 'nonstop_check': 0, 'hetvege_check': 0} |
31
|
|
|
self.filetype = FileType.json |
32
|
|
|
self.filename = '{}.{}'.format( |
33
|
|
|
self.__class__.__name__, self.filetype.name) |
34
|
|
|
|
35
|
|
|
def types(self): |
36
|
|
|
hukulcspha = self.tags.copy() |
37
|
|
|
hukulcspha.update(POS_HU_GEN) |
38
|
|
|
hukulcspha.update(PAY_CASH) |
39
|
|
|
self.__types = [ |
40
|
|
|
{'poi_code': 'hukulcspha', 'poi_name': 'Kulcs Patika', 'poi_type': 'pharmacy', |
41
|
|
|
'poi_tags': hukulcspha, |
42
|
|
|
'poi_url_base': 'https://www.kulcspatika.hu/', 'poi_search_name': '(kulcs patika|kulcs)', |
|
|
|
|
43
|
|
|
'preserve_original_name': True}, |
44
|
|
|
] |
45
|
|
|
return self.__types |
46
|
|
|
|
47
|
|
|
def process(self): |
48
|
|
|
try: |
49
|
|
|
if self.link: |
50
|
|
|
# soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, |
|
|
|
|
51
|
|
|
# self.filename), self.post, self.verify_link, headers=self.headers) |
|
|
|
|
52
|
|
|
with open(os.path.join(self.download_cache, self.filename), 'r') as f: |
|
|
|
|
53
|
|
|
text = json.load(f) |
54
|
|
|
if text is not None: |
55
|
|
|
text = json.loads(text, strict=False) |
56
|
|
|
for poi_data in text: |
57
|
|
|
try: |
58
|
|
|
if 'Kulcs patika' not in poi_data.get('nev'): |
59
|
|
|
self.data.name = poi_data.get( |
60
|
|
|
'nev').strip() |
61
|
|
|
self.data.branch = None |
62
|
|
|
else: |
63
|
|
|
self.data.name = 'Kulcs patika' |
64
|
|
|
self.data.branch = poi_data.get( |
65
|
|
|
'nev').strip() |
66
|
|
|
self.data.code = 'hukulcspha' |
67
|
|
|
if poi_data.get('link') is not None and poi_data.get('link') != '': |
68
|
|
|
self.data.website = poi_data.get('link').strip() if poi_data.get('link') \ |
|
|
|
|
69
|
|
|
is not None else None |
70
|
|
|
if poi_data.get('helyseg') is not None and poi_data.get('helyseg') != '': |
|
|
|
|
71
|
|
|
self.data.city = clean_city( |
72
|
|
|
poi_data.get('helyseg')) |
73
|
|
|
self.data.lat, self.data.lon = \ |
74
|
|
|
check_hu_boundary(poi_data.get('marker_position')['latitude'], |
75
|
|
|
poi_data.get('marker_position')['longitude']) |
76
|
|
|
if poi_data.get('cim') is not None and poi_data.get('cim') != '': |
77
|
|
|
self.data.original = poi_data.get('cim') |
78
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
|
|
|
|
79
|
|
|
extract_street_housenumber_better_2( |
80
|
|
|
poi_data.get('cim')) |
81
|
|
|
if poi_data.get('irsz') is not None and poi_data.get('irsz') != '': |
82
|
|
|
self.data.postcode = poi_data.get( |
83
|
|
|
'irsz').strip() |
84
|
|
|
self.data.public_holiday_open = False |
85
|
|
|
self.data.add() |
86
|
|
|
except Exception as e: |
|
|
|
|
87
|
|
|
logging.error(e) |
88
|
|
|
logging.error(poi_data) |
89
|
|
|
logging.exception('Exception occurred') |
90
|
|
|
|
91
|
|
|
except Exception as e: |
|
|
|
|
92
|
|
|
logging.error(e) |
93
|
|
|
logging.exception('Exception occurred') |
94
|
|
|
|