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.soup import save_downloaded_soup |
9
|
|
|
from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city, clean_phone_to_str |
|
|
|
|
10
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
11
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH |
12
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
13
|
|
|
from osm_poi_matchmaker.utils.enums import FileType |
14
|
|
|
except ImportError as err: |
15
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
16
|
|
|
logging.exception('Exception occurred') |
17
|
|
|
|
18
|
|
|
sys.exit(128) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class hu_dm(DataProvider): |
|
|
|
|
22
|
|
|
|
23
|
|
|
def constains(self): |
24
|
|
|
self.link = 'https://services.dm.de/storedata/stores/bbox/49%2C16%2C45%2C23' |
25
|
|
|
self.tags = {'shop': 'chemist', 'operator': 'dm Kft.', 'brand': 'dm', |
26
|
|
|
'brand:wikidata': 'Q266572', 'brand:wikipedia': 'en:Dm-drogerie markt', |
27
|
|
|
'contact:facebook': 'https://www.facebook.com/dm.Magyarorszag', |
28
|
|
|
'contact:youtube': 'https://www.youtube.com/user/dmMagyarorszag', |
29
|
|
|
'contact:instagram': 'https://www.instagram.com/dm_magyarorszag', |
30
|
|
|
'ref:vatin': 'HU11181530', 'ref:vatin:hu': '11181530-2-44', 'ref:HU:company': '13 09 078006', |
|
|
|
|
31
|
|
|
'air_conditioning': 'yes'} |
32
|
|
|
self.filetype = FileType.json |
33
|
|
|
self.filename = '{}.{}'.format( |
34
|
|
|
self.__class__.__name__, self.filetype.name) |
35
|
|
|
|
36
|
|
|
def types(self): |
37
|
|
|
hudmche = self.tags.copy() |
38
|
|
|
hudmche.update(POS_HU_GEN) |
39
|
|
|
hudmche.update(PAY_CASH) |
40
|
|
|
self.__types = [ |
41
|
|
|
{'poi_code': 'hudmche', 'poi_name': 'dm', 'poi_type': 'chemist', |
42
|
|
|
'poi_tags': hudmche, 'poi_url_base': 'https://www.dm.hu', 'poi_search_name': 'dm', |
43
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, |
44
|
|
|
'osm_search_distance_unsafe': 15}, |
45
|
|
|
] |
46
|
|
|
return self.__types |
47
|
|
|
|
48
|
|
|
def process(self): |
49
|
|
|
try: |
|
|
|
|
50
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
51
|
|
|
self.filetype) |
52
|
|
|
if soup is not None: |
53
|
|
|
text = json.loads(soup) |
54
|
|
|
for poi_data in text['stores']: |
55
|
|
|
try: |
56
|
|
|
if poi_data.get('localeCountry').strip().upper() == 'HU': |
57
|
|
|
self.data.name = 'dm' |
58
|
|
|
self.data.code = 'hudmche' |
59
|
|
|
self.data.postcode = poi_data.get('address')[ |
60
|
|
|
'zip'].strip() |
61
|
|
|
street_tmp = poi_data.get( |
62
|
|
|
'address')['street'].split(',')[0] |
63
|
|
|
self.data.city = clean_city( |
64
|
|
|
poi_data.get('address')['city']) |
65
|
|
|
self.data.website = 'https://www.dm.hu{}'.format( |
66
|
|
|
poi_data.get('storeUrlPath')) |
67
|
|
|
self.data.original = poi_data.get('address')[ |
68
|
|
|
'street'] |
69
|
|
|
self.data.lat, self.data.lon = \ |
70
|
|
|
check_hu_boundary(poi_data.get('location')[ |
71
|
|
|
'lat'], poi_data.get('location')['lon']) |
|
|
|
|
72
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
|
|
|
|
73
|
|
|
extract_street_housenumber_better_2( |
74
|
|
|
street_tmp.title()) |
75
|
|
|
if poi_data.get('phone') is not None and poi_data.get('phone') != '': |
76
|
|
|
self.data.phone = clean_phone_to_str( |
77
|
|
|
poi_data.get('phone')) |
78
|
|
|
if poi_data.get('storeNumber') is not None and poi_data.get('storeNumber') != '': |
|
|
|
|
79
|
|
|
self.data.ref = poi_data.get( |
80
|
|
|
'storeNumber').strip() |
81
|
|
|
opening = poi_data.get('openingDays') |
82
|
|
|
try: |
83
|
|
|
for i, d in enumerate(opening): |
|
|
|
|
84
|
|
|
if d.get('weekDay') is not None and 1 <= d.get('weekDay') <= 7: |
85
|
|
|
day = d.get('weekDay') |
86
|
|
|
self.data.day_open( |
87
|
|
|
day - 1, d.get('timeSlices')[0].get('opening')) |
88
|
|
|
self.data.day_close( |
89
|
|
|
day - 1, d.get('timeSlices')[0].get('closing')) |
90
|
|
|
except (IndexError, KeyError): |
91
|
|
|
logging.warning( |
92
|
|
|
'Exception occurred during opening hours processing') |
93
|
|
|
self.data.public_holiday_open = False |
94
|
|
|
self.data.add() |
95
|
|
|
except Exception as e: |
|
|
|
|
96
|
|
|
logging.error(e) |
97
|
|
|
logging.error(poi_data) |
98
|
|
|
logging.exception('Exception occurred') |
99
|
|
|
|
100
|
|
|
except Exception as e: |
|
|
|
|
101
|
|
|
logging.error(e) |
102
|
|
|
logging.exception('Exception occurred') |
103
|
|
|
|