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 import query_osm_city_name_gpd |
12
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
13
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_OTP, PAY_CASH |
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_tesco(DataProvider): |
|
|
|
|
23
|
|
|
|
24
|
|
|
def constains(self): |
25
|
|
|
self.link = 'https://tesco.hu/Ajax?type=fetch-stores-for-area&reduceBy%5Btab%5D=all&bounds%5Bnw%5D%5Blat%5D=49.631214952216425&bounds%5Bnw%5D%5Blng%5D=11.727758183593778&bounds%5Bne%5D%5Blat%5D=49.631214952216425&bounds%5Bne%5D%5Blng%5D=27.004247441406278&bounds%5Bsw%5D%5Blat%5D=38.45256463471463&bounds%5Bsw%5D%5Blng%5D=11.727758183593778&bounds%5Bse%5D%5Blat%5D=38.45256463471463&bounds%5Bse%5D%5Blng%5D=27.004247441406278¤tCoords%5Blat%5D=44.30719090363816¤tCoords%5Blng%5D=19.366002812500028&instanceUUID=b5c4aa5f-9819-47d9-9e5a-d631e931c007' |
|
|
|
|
26
|
|
|
self.tags = {'operator': 'TESCO-GLOBAL Áruházak Zrt.', |
27
|
|
|
'operator:addr': '2040 Budaörs, Kinizsi út 1-3.', |
28
|
|
|
'ref:HU:company': '13-10-040628', 'ref:vatin:hu': '10307078-2-44', |
29
|
|
|
'ref:vatin': 'HU10307078', 'brand': 'Tesco', |
30
|
|
|
'brand:wikipedia': 'hu:Tesco', 'brand:wikidata': 'Q487494', |
31
|
|
|
'internet_access': 'wlan', 'internet_access:fee': 'no', |
32
|
|
|
'internet_access:ssid': 'tesco-internet', |
33
|
|
|
'contact:facebook': 'https://www.facebook.com/tescoaruhazak', |
34
|
|
|
'contact:pinterest': 'https://www.pinterest.com/tescohungary/', |
35
|
|
|
'contact:youtube': 'https://www.youtube.com/user/TescoMagyarorszag', |
36
|
|
|
'loyalty_card': 'yes', 'payment:gift_card': 'yes', 'payment:wire_transfer': 'yes', |
|
|
|
|
37
|
|
|
'air_conditioning': 'yes'} |
38
|
|
|
self.tags.update(POS_OTP) |
39
|
|
|
self.tags.update(PAY_CASH) |
40
|
|
|
self.filetype = FileType.json |
41
|
|
|
self.filename = '{}.{}'.format( |
42
|
|
|
self.__class__.__name__, self.filetype.name) |
43
|
|
|
|
44
|
|
|
def types(self): |
45
|
|
|
hutescoexp = {'shop': 'convenience'} |
46
|
|
|
hutescoexp.update(self.tags) |
47
|
|
|
hutescoext = {'shop': 'supermarket', |
48
|
|
|
'wheelchair': 'yes', 'source:wheelchair': 'website'} |
49
|
|
|
hutescoext.update(self.tags) |
50
|
|
|
hutescosup = {'shop': 'supermarket', |
51
|
|
|
'wheelchair': 'yes', 'source:wheelchair': 'website'} |
52
|
|
|
hutescosup.update(self.tags) |
53
|
|
|
husmrktexp = {'shop': 'convenience', 'alt_name': 'Tesco Expressz'} |
54
|
|
|
husmrktexp.update(self.tags) |
55
|
|
|
husmrktsup = {'shop': 'supermarket', 'wheelchair': 'yes', |
56
|
|
|
'source:wheelchair': 'website', 'alt_name': 'Tesco'} |
57
|
|
|
husmrktsup.update(self.tags) |
58
|
|
|
self.__types = [ |
59
|
|
|
{'poi_code': 'hutescoexp', 'poi_name': 'Tesco Expressz', 'poi_type': 'shop', |
60
|
|
|
'poi_tags': hutescoexp, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco', |
61
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200}, |
62
|
|
|
{'poi_code': 'hutescoext', 'poi_name': 'Tesco Extra', 'poi_type': 'shop', |
63
|
|
|
'poi_tags': hutescoext, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco', |
64
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 1100}, |
65
|
|
|
{'poi_code': 'hutescosup', 'poi_name': 'Tesco', 'poi_type': 'shop', |
66
|
|
|
'poi_tags': hutescosup, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco', |
67
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 1100}, |
68
|
|
|
{'poi_code': 'husmrktexp', 'poi_name': 'S-Market', 'poi_type': 'shop', |
69
|
|
|
'poi_tags': husmrktexp, 'poi_url_base': 'https://tesco.hu', |
70
|
|
|
'poi_search_name': '(tesco|smarket|s-market|s market)', |
71
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200}, |
72
|
|
|
{'poi_code': 'husmrktsup', 'poi_name': 'S-Market', 'poi_type': 'shop', |
73
|
|
|
'poi_tags': husmrktsup, 'poi_url_base': 'https://tesco.hu', |
74
|
|
|
'poi_search_name': '(tesco|smarket|s-market|s market)', |
75
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200}, |
76
|
|
|
] |
77
|
|
|
return self.__types |
78
|
|
|
|
79
|
|
|
def process(self): |
80
|
|
|
try: |
|
|
|
|
81
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
82
|
|
|
self.filetype) |
83
|
|
|
if soup is not None: |
84
|
|
|
# parse the html using beautiful soap and store in variable `soup` |
85
|
|
|
# script = soup.find('div', attrs={'data-stores':True}) |
86
|
|
|
text = json.loads(str(soup)) |
87
|
|
|
for poi_data in text.get('stores'): |
88
|
|
|
try: |
89
|
|
|
# Assign: code, postcode, city, name, branch, website, original, street, housenumber, |
|
|
|
|
90
|
|
|
# conscriptionnumber, ref, geom |
91
|
|
|
self.data.branch = poi_data.get('store_name') |
92
|
|
|
self.data.ref = poi_data.get('goldid') |
93
|
|
|
self.data.website = 'https://tesco.hu/aruhazak/aruhaz/{}/'.format( |
94
|
|
|
poi_data.get('urlname')) |
95
|
|
|
opening = json.loads(poi_data.get('opening')) |
96
|
|
|
for i in range(0, 7): |
97
|
|
|
ind = str(i + 1) if i != 6 else '0' |
98
|
|
|
if ind in opening: |
99
|
|
|
self.data.day_open(i, opening[ind][0]) |
100
|
|
|
self.data.day_close(i, opening[ind][1]) |
101
|
|
|
self.data.lat, self.data.lon = check_hu_boundary( |
102
|
|
|
poi_data.get('gpslat'), poi_data.get('gpslng')) |
103
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
104
|
|
|
extract_street_housenumber_better_2( |
105
|
|
|
poi_data.get('address')) |
106
|
|
|
self.data.postcode = poi_data.get('zipcode').strip() |
107
|
|
|
self.data.city = clean_city(query_osm_city_name_gpd( |
108
|
|
|
self.session, self.data.lat, self.data.lon)) |
109
|
|
|
if 'xpres' in poi_data.get('name'): |
110
|
|
|
if self.data.city not in ['Győr', 'Sopron', 'Mosonmagyaróvár', 'Levél']: |
111
|
|
|
self.data.name = 'Tesco Expressz' |
112
|
|
|
self.data.code = 'hutescoexp' |
113
|
|
|
else: |
114
|
|
|
self.data.name = 'S-Market' |
115
|
|
|
self.data.code = 'husmrktexp' |
116
|
|
|
elif 'xtra' in poi_data.get('name'): |
117
|
|
|
self.data.name = 'Tesco Extra' |
118
|
|
|
self.data.code = 'hutescoext' |
119
|
|
|
else: |
120
|
|
|
if self.data.city not in ['Levél']: |
121
|
|
|
self.data.name = 'Tesco' |
122
|
|
|
self.data.code = 'hutescosup' |
123
|
|
|
else: |
124
|
|
|
self.data.name = 'S-Market' |
125
|
|
|
self.data.code = 'husmrktsup' |
126
|
|
|
self.data.original = poi_data.get('address') |
127
|
|
|
if poi_data.get('phone') is not None and poi_data.get('phone') != '': |
128
|
|
|
self.data.phone = clean_phone_to_str( |
129
|
|
|
poi_data.get('phone')) |
130
|
|
|
if poi_data.get('goldid') is not None and poi_data.get('goldid') != '': |
131
|
|
|
self.data.ref = poi_data.get('goldid').strip() |
132
|
|
|
self.data.public_holiday_open = False |
133
|
|
|
self.data.add() |
134
|
|
|
except Exception as e: |
|
|
|
|
135
|
|
|
logging.error(e) |
136
|
|
|
logging.error(poi_data) |
137
|
|
|
logging.exception('Exception occurred') |
138
|
|
|
|
139
|
|
|
except Exception as e: |
|
|
|
|
140
|
|
|
logging.error(e) |
141
|
|
|
logging.exception('Exception occurred') |
142
|
|
|
|