1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
import logging |
5
|
|
|
import sys |
6
|
|
|
import os |
7
|
|
|
import re |
8
|
|
|
import json |
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 |
11
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
12
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_OTP, 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
|
|
|
PATTERN_SPAR_REF = re.compile('\((.*?)\)') |
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class hu_spar(DataProvider): |
|
|
|
|
25
|
|
|
|
26
|
|
|
def constains(self): |
27
|
|
|
self.link = 'https://www.spar.hu/uzletek/_jcr_content.stores.v2' |
28
|
|
|
self.tags = {'operator': 'SPAR Magyarország Kereskedelmi Kft.', 'brand': 'Spar', |
29
|
|
|
'brand:wikipedia': 'hu:Spar', 'brand:wikidata': 'Q610492', |
30
|
|
|
'contact:email': '[email protected]', |
31
|
|
|
'phone': '+36208237727', 'contact:facebook': 'https://www.facebook.com/sparmagyarorszag', |
|
|
|
|
32
|
|
|
'contact:youtube': 'https://www.youtube.com/channel/UC9tu8COHiy4WkeTIN1k_Y8A', |
33
|
|
|
'contact:instagram': 'https://www.instagram.com/sparmagyarorszag'} |
34
|
|
|
self.tags.update(POS_OTP) |
35
|
|
|
self.tags.update(PAY_CASH) |
36
|
|
|
self.filetype = FileType.json |
37
|
|
|
self.filename = '{}.{}'.format( |
38
|
|
|
self.__class__.__name__, self.filetype.name) |
39
|
|
|
|
40
|
|
|
def types(self): |
41
|
|
|
husparecon = {'shop': 'convenience'} |
42
|
|
|
husparecon.update(self.tags) |
43
|
|
|
husparisup = {'shop': 'supermarket'} |
44
|
|
|
husparisup.update(self.tags) |
45
|
|
|
husparsup = {'shop': 'supermarket'} |
46
|
|
|
husparsup.update(self.tags) |
47
|
|
|
huspardcon = {'shop': 'convenience'} |
48
|
|
|
huspardcon.update(self.tags) |
49
|
|
|
self.__types = [ |
50
|
|
|
{'poi_code': 'husparecon', 'poi_name': 'Spar Expressz', 'poi_type': 'shop', |
51
|
|
|
'poi_tags': husparecon, 'poi_url_base': 'https://www.spar.hu', |
52
|
|
|
'poi_search_name': '(spar|spar express|spar expressz)', |
53
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15}, |
|
|
|
|
54
|
|
|
{'poi_code': 'husparisup', 'poi_name': 'Interspar', 'poi_type': 'shop', |
55
|
|
|
'poi_tags': husparisup, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|interspar)', |
|
|
|
|
56
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15}, |
|
|
|
|
57
|
|
|
{'poi_code': 'husparsup', 'poi_name': 'Spar', 'poi_type': 'shop', |
58
|
|
|
'poi_tags': husparsup, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|spar supermarket)', |
|
|
|
|
59
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15}, |
|
|
|
|
60
|
|
|
{'poi_code': 'huspardcon', 'poi_name': 'DeSpar', 'poi_type': 'shop', |
61
|
|
|
'poi_tags': huspardcon, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|despar)', |
|
|
|
|
62
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15}, |
|
|
|
|
63
|
|
|
] |
64
|
|
|
return self.__types |
65
|
|
|
|
66
|
|
|
def process(self): |
67
|
|
|
try: |
68
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
69
|
|
|
self.filetype) |
70
|
|
|
if soup is not None: |
71
|
|
|
text = json.loads(soup) |
72
|
|
|
for poi_data in text: |
73
|
|
|
# Assign: code, postcode, city, name, branch, website, original, street, housenumber, conscriptionnumber, ref, geom |
|
|
|
|
74
|
|
|
if 'xpres' in poi_data['name']: |
75
|
|
|
self.data.name = 'Spar Expressz' |
76
|
|
|
self.data.code = 'husparecon' |
77
|
|
|
elif 'INTER' in poi_data['name']: |
78
|
|
|
self.data.name = 'Interspar' |
79
|
|
|
self.data.code = 'husparisup' |
80
|
|
|
elif 'market' in poi_data['name']: |
81
|
|
|
self.data.name = 'Spar' |
82
|
|
|
self.data.code = 'husparsup' |
83
|
|
|
elif 'DESPAR' in poi_data['name']: |
84
|
|
|
self.data.name = 'DeSpar' |
85
|
|
|
self.data.code = 'huspardcon' |
86
|
|
|
else: |
87
|
|
|
self.data.name = 'Spar' |
88
|
|
|
self.data.code = 'husparsup' |
89
|
|
|
poi_data['name'] = poi_data['name'].replace( |
90
|
|
|
'INTERSPAR', 'Interspar') |
91
|
|
|
poi_data['name'] = poi_data['name'].replace('SPAR', 'Spar') |
92
|
|
|
ref_match = PATTERN_SPAR_REF.search(poi_data['name']) |
93
|
|
|
self.data.ref = ref_match.group( |
94
|
|
|
1).strip() if ref_match is not None else None |
95
|
|
|
self.data.city = clean_city(poi_data['city']) |
96
|
|
|
self.data.postcode = poi_data.get('zipCode').strip() |
97
|
|
|
self.data.branch = poi_data['name'].split('(')[0].strip() |
98
|
|
|
self.data.website = poi_data['pageUrl'].strip() |
99
|
|
|
self.data.lat, self.data.lon = check_hu_boundary( |
100
|
|
|
poi_data['latitude'], poi_data['longitude']) |
101
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = extract_street_housenumber_better_2( |
|
|
|
|
102
|
|
|
poi_data['address']) |
103
|
|
|
self.data.original = poi_data['address'] |
104
|
|
|
self.data.public_holiday_open = False |
105
|
|
|
self.data.add() |
106
|
|
|
except Exception as e: |
|
|
|
|
107
|
|
|
logging.exception('Exception occurred') |
108
|
|
|
|
109
|
|
|
logging.error(e) |
110
|
|
|
|