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
|
|
|
clean_email |
11
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
12
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH |
13
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
14
|
|
|
from osm_poi_matchmaker.utils.enums import FileType |
15
|
|
|
except ImportError as err: |
16
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
17
|
|
|
logging.exception('Exception occurred') |
18
|
|
|
|
19
|
|
|
sys.exit(128) |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class hu_obi(DataProvider): |
|
|
|
|
23
|
|
|
|
24
|
|
|
def constains(self): |
25
|
|
|
self.link = 'https://www.obi.hu/storeLocatorRest/v1/stores/getAllByCountry/hu/hu?fields=name,address,phone,services,hours,storeNumber,path,email' |
|
|
|
|
26
|
|
|
self.tags = {'shop': 'doityourself', 'brand': 'OBI', 'brand:wikidata': 'Q300518', |
27
|
|
|
'brand:wikipedia': 'en:Obi (store)', 'operator': 'OBI Hungary Retail Kft.', |
28
|
|
|
'operator:addr': '1097 Budapest, Könyves Kálmán körút 12-14', |
29
|
|
|
'ref:vatin:hu': '13136062-2-44', 'ref:vatin': 'HU13136062', |
30
|
|
|
'wheelchair': 'yes', 'air_conditioning': 'yes', } |
31
|
|
|
self.filetype = FileType.json |
32
|
|
|
self.filename = '{}.{}'.format( |
33
|
|
|
self.__class__.__name__, self.filetype.name) |
34
|
|
|
|
35
|
|
|
def types(self): |
36
|
|
|
huobidiy = self.tags.copy() |
37
|
|
|
huobidiy.update(POS_HU_GEN) |
38
|
|
|
huobidiy.update(PAY_CASH) |
39
|
|
|
self.__types = [ |
40
|
|
|
{'poi_code': 'huobidiy', 'poi_name': 'OBI', 'poi_type': 'doityourself', |
41
|
|
|
'poi_tags': huobidiy, 'poi_url_base': 'https://www.obi.hu', 'poi_search_name': 'obi', |
42
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15}, |
|
|
|
|
43
|
|
|
] |
44
|
|
|
return self.__types |
45
|
|
|
|
46
|
|
|
def process(self): |
47
|
|
|
try: |
48
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
49
|
|
|
self.filetype) |
50
|
|
|
if soup is not None: |
51
|
|
|
text = json.loads(soup) |
52
|
|
|
for poi_data in text.get('stores'): |
53
|
|
|
self.data.name = 'OBI' |
54
|
|
|
self.data.code = 'huobidiy' |
55
|
|
|
self.data.postcode = poi_data['address']['zip'].strip() |
56
|
|
|
self.data.city = clean_city(poi_data['address']['city']) |
57
|
|
|
self.data.original = poi_data['address']['street'] |
58
|
|
|
self.data.lat, self.data.lon = check_hu_boundary(poi_data['address']['lat'], |
59
|
|
|
poi_data['address']['lon']) |
60
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = extract_street_housenumber_better_2( |
|
|
|
|
61
|
|
|
poi_data['address']['street']) |
62
|
|
|
if 'phone' in poi_data and poi_data.get('phone') != '': |
63
|
|
|
self.data.phone = clean_phone_to_str( |
64
|
|
|
poi_data.get('phone')) |
65
|
|
|
if 'storeNumber' in poi_data and poi_data.get('storeNumber') != '': |
66
|
|
|
self.data.ref = poi_data.get('storeNumber').strip() |
67
|
|
|
if 'email' in poi_data and poi_data.get('email') != '': |
68
|
|
|
self.data.email = clean_email(poi_data.get('email')) |
69
|
|
|
if 'path' in poi_data and poi_data.get('path') != '': |
70
|
|
|
self.data.website = poi_data.get('path') |
71
|
|
|
# TODO: opening hour parser for poi_data.get('hours'), format is like: |
|
|
|
|
72
|
|
|
# Hétfő - Szombat: 8:00 - 20:00\nVasárnap: 08:00 - 18:00 |
73
|
|
|
# self.data.public_holiday_open = False |
74
|
|
|
self.data.add() |
75
|
|
|
except Exception as e: |
|
|
|
|
76
|
|
|
logging.exception('Exception occurred') |
77
|
|
|
|
78
|
|
|
logging.error(e) |
79
|
|
|
|