|
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 |
|
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_pepco(DataProvider): |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def constains(self): |
|
25
|
|
|
self.link = 'https://pepco.hu/uzleteink/uzletkereso/?type=1002&tx_pepco_mapplugin[action]=view&tx_pepco_mapplugin[controller]=Map&tx_pepco_mapplugin[loadall]=true' |
|
|
|
|
|
|
26
|
|
|
self.tags = {'shop': 'clothes', 'brand': 'Pepco', 'brand:wikidata': 'Q11815580', |
|
27
|
|
|
'brand:wikipedia': 'pl:Pepco', 'contact:facebook': 'https://www.facebook.com/pepcohu/', |
|
|
|
|
|
|
28
|
|
|
'contact:website': 'https://pepco.hu/', |
|
29
|
|
|
'contact:linkedin': 'https://www.linkedin.com/company/pepco-poland', |
|
30
|
|
|
'contact:phone': '+36 1 701 0424', 'contact:email': '[email protected]', |
|
31
|
|
|
'operator': 'Pepkor Hungary Kft.', 'operator:addr': '1138 Budapest, Váci út 187.'} |
|
|
|
|
|
|
32
|
|
|
self.filetype = FileType.json |
|
33
|
|
|
self.filename = '{}.{}'.format( |
|
34
|
|
|
self.__class__.__name__, self.filetype.name) |
|
35
|
|
|
|
|
36
|
|
|
def types(self): |
|
37
|
|
|
hupepcoclo = self.tags.copy() |
|
38
|
|
|
hupepcoclo.update(POS_HU_GEN) |
|
39
|
|
|
hupepcoclo.update(PAY_CASH) |
|
40
|
|
|
self.__types = [ |
|
41
|
|
|
{'poi_code': 'hupepcoclo', 'poi_name': 'Pepco', 'poi_type': 'clothes', |
|
42
|
|
|
'poi_tags': hupepcoclo, 'poi_url_base': 'https://pepco.hu', 'poi_search_name': 'pepco', |
|
43
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, |
|
44
|
|
|
'osm_search_distance_unsafe': 5}, |
|
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['data']: |
|
55
|
|
|
''' |
|
56
|
|
|
The Pepco dataset contains all European data. Since the program cannot handle POIs outside Hungary (so far) |
|
|
|
|
|
|
57
|
|
|
this will limit only for Hungarian POIs |
|
58
|
|
|
In fact this depends on OSM extract but currently we use only Hungarian OSM extract |
|
|
|
|
|
|
59
|
|
|
Select only Hungarian POIs |
|
60
|
|
|
''' |
|
|
|
|
|
|
61
|
|
|
if 'city' in poi_data and (poi_data['city'] == '' or |
|
|
|
|
|
|
62
|
|
|
query_osm_city_name(self.session, poi_data['city']) is None): |
|
|
|
|
|
|
63
|
|
|
continue |
|
64
|
|
|
elif 'city' in poi_data: |
|
65
|
|
|
self.data.city = clean_city(poi_data['city']) |
|
66
|
|
|
else: |
|
67
|
|
|
continue |
|
68
|
|
|
self.data.name = 'Pepco' |
|
69
|
|
|
self.data.code = 'hupepcoclo' |
|
70
|
|
|
# Assign: code, postcode, city, name, branch, website, original, street, housenumber, conscriptionnumber, ref, geom |
|
|
|
|
|
|
71
|
|
|
self.data.lat, self.data.lon = \ |
|
72
|
|
|
check_hu_boundary( |
|
73
|
|
|
poi_data['coordinates']['lat'], poi_data['coordinates']['lng']) |
|
74
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
|
75
|
|
|
extract_street_housenumber_better_2( |
|
76
|
|
|
poi_data.get('streetAddress')) |
|
77
|
|
|
self.data.original = poi_data.get('streetAddress') |
|
78
|
|
|
self.data.postcode = poi_data.get('postalCode') |
|
79
|
|
|
# self.data.city = query_osm_city_name_gpd(self.session, self.data.lat, self.data.lon) |
|
|
|
|
|
|
80
|
|
|
# Assign opening_hours |
|
81
|
|
|
opening = poi_data['openingHours'] |
|
82
|
|
|
for i in range(0, 7): |
|
83
|
|
|
if i in opening: |
|
84
|
|
|
self.data.day_open(i, opening[i]['from']) |
|
85
|
|
|
self.data.day_close(i, opening[i]['to']) |
|
86
|
|
|
# Assign additional informations |
|
87
|
|
|
self.data.phone = clean_phone_to_str( |
|
88
|
|
|
poi_data.get('phoneNumber')) |
|
89
|
|
|
self.data.public_holiday_open = False |
|
90
|
|
|
self.data.add() |
|
91
|
|
|
except Exception as e: |
|
|
|
|
|
|
92
|
|
|
logging.exception('Exception occurred') |
|
93
|
|
|
|
|
94
|
|
|
logging.error(logging.error(e)) |
|
95
|
|
|
|