|
1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
try: |
|
4
|
|
|
import logging |
|
5
|
|
|
import sys |
|
6
|
|
|
import os |
|
7
|
|
|
import json |
|
8
|
|
|
from osm_poi_matchmaker.dao.data_handlers import insert_poi_dataframe |
|
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.poi_dataset import POIDataset |
|
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
|
|
|
POI_POSTA = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=posta' |
|
|
|
|
|
|
21
|
|
|
POI_CSEKK = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=csekkautomata', |
|
|
|
|
|
|
22
|
|
|
POI_CSOMAG = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=postamachine', |
|
|
|
|
|
|
23
|
|
|
POI_POSTA_PONT = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=postapoint', |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class hu_posta_json(DataProvider): |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def __init__(self, session, link, download_cache, filename='hu_posta.json'): |
|
|
|
|
|
|
29
|
|
|
self.session = session |
|
30
|
|
|
self.link = link |
|
31
|
|
|
self.tags = {'brand': 'Magyar Posta', 'operator': 'Magyar Posta Zrt.', 'ref:vatin:hu': '10901232-2-44', |
|
|
|
|
|
|
32
|
|
|
'ref:vatin': 'HU10901232', 'brand:wikipedia': 'hu:Magyar Posta Zrt.', 'brand:wikidata': 'Q145614', |
|
|
|
|
|
|
33
|
|
|
'contact:email': '[email protected]', 'phone': '+3617678200', |
|
34
|
|
|
'contact:facebook': 'https://www.facebook.com/MagyarPosta', |
|
35
|
|
|
'contact:youtube': 'https://www.youtube.com/user/magyarpostaofficial', |
|
36
|
|
|
'contact:instagram': 'https://www.instagram.com/magyar_posta_zrt/', |
|
37
|
|
|
'payment:cash': 'yes', 'payment:debit_cards': 'yes'} |
|
38
|
|
|
self.filetype = FileType.json |
|
39
|
|
|
self.filename = '{}.{}'.format( |
|
40
|
|
|
self.__class__.__name__, self.filetype.name) |
|
41
|
|
|
self.download_cache = download_cache |
|
42
|
|
|
self.filename = filename |
|
43
|
|
|
|
|
44
|
|
|
def types(self): |
|
45
|
|
|
hupostapo = {'amenity': 'post_office'} |
|
46
|
|
|
hupostapo.update(self.tags) |
|
47
|
|
|
hupostacse = {'amenity': 'vending_machine', 'vending': 'cheques'} |
|
48
|
|
|
hupostacse.update(self.tags) |
|
49
|
|
|
hupostacso = {'amenity': 'vending_machine', 'vending': 'parcel_pickup'} |
|
50
|
|
|
hupostacso.update(self.tags) |
|
51
|
|
|
hupostapp = {'amenity': 'post_office'} |
|
52
|
|
|
hupostapp.update(self.tags) |
|
53
|
|
|
hupostamp = {'amenity': 'post_office'} |
|
54
|
|
|
hupostamp.update(self.tags) |
|
55
|
|
|
|
|
56
|
|
|
data = [ |
|
57
|
|
|
{'poi_code': 'hupostapo', 'poi_name': 'Posta', 'poi_type': 'post_office', |
|
58
|
|
|
'poi_tags': hupostapo, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'}, |
|
|
|
|
|
|
59
|
|
|
{'poi_code': 'hupostacse', 'poi_name': 'Posta csekkautomata', 'poi_type': 'vending_machine_cheques', |
|
|
|
|
|
|
60
|
|
|
'poi_tags': hupostacse, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'}, |
|
|
|
|
|
|
61
|
|
|
{'poi_code': 'hupostacso', 'poi_name': 'Posta csomagautomata', |
|
62
|
|
|
'poi_type': 'vending_machine_parcel_pickup', |
|
63
|
|
|
'poi_tags': hupostacso, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': '(mpl|posta)'}, |
|
|
|
|
|
|
64
|
|
|
{'poi_code': 'hupostapp', 'poi_name': 'PostaPont', 'poi_type': 'post_office', |
|
65
|
|
|
'poi_tags': hupostapp, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': '(postapont|posta)'}, |
|
|
|
|
|
|
66
|
|
|
{'poi_code': 'hupostamp', 'poi_name': 'Mobilposta', 'poi_type': 'post_office', |
|
67
|
|
|
'poi_tags': hupostamp, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'}] |
|
|
|
|
|
|
68
|
|
|
return data |
|
69
|
|
|
|
|
70
|
|
|
def process(self): |
|
71
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
|
|
72
|
|
|
self.filetype) |
|
73
|
|
|
if soup is not None: |
|
74
|
|
|
text = json.loads(soup) |
|
75
|
|
|
data = POIDataset() |
|
76
|
|
|
for poi_data in text['items']: |
|
77
|
|
|
if poi_data['type'] == 'posta': |
|
78
|
|
|
if 'mobilposta' in poi_data['name']: |
|
79
|
|
|
data.name = 'Mobilposta' |
|
80
|
|
|
data.code = 'hupostamp' |
|
81
|
|
|
else: |
|
82
|
|
|
data.name = 'Posta' |
|
83
|
|
|
data.code = 'hupostapo' |
|
84
|
|
|
data.public_holiday_open = False |
|
85
|
|
|
elif poi_data['type'] == 'csekkautomata': |
|
86
|
|
|
data.name = 'Posta csekkautomata' |
|
87
|
|
|
data.code = 'hupostacse' |
|
88
|
|
|
data.public_holiday_open = True |
|
89
|
|
|
elif poi_data['type'] == 'postamachine': |
|
90
|
|
|
data.name = 'Posta csomagautomata' |
|
91
|
|
|
data.code = 'hupostacso' |
|
92
|
|
|
data.public_holiday_open = True |
|
93
|
|
|
elif poi_data['type'] == 'postapoint': |
|
94
|
|
|
data.name = 'PostaPont' |
|
95
|
|
|
data.code = 'hupostapp' |
|
96
|
|
|
data.public_holiday_open = False |
|
97
|
|
|
else: |
|
98
|
|
|
logging.error('Non existing Posta type.') |
|
99
|
|
|
data.postcode = poi_data['zipCode'].strip() |
|
100
|
|
|
data.city = clean_city(poi_data['city']) |
|
101
|
|
|
data.branch = poi_data['name'] |
|
102
|
|
|
data.lat = poi_data['lat'] |
|
103
|
|
|
data.lon = poi_data['lng'] |
|
104
|
|
|
data.street, data.housenumber, data.conscriptionnumber = extract_street_housenumber_better_2( |
|
|
|
|
|
|
105
|
|
|
poi_data['address']) |
|
106
|
|
|
data.original = poi_data['address'] |
|
107
|
|
|
data.add() |
|
108
|
|
|
if data is None or data.lenght() < 1: |
|
109
|
|
|
logging.warning('Resultset is empty. Skipping ...') |
|
110
|
|
|
else: |
|
111
|
|
|
insert_poi_dataframe(self.session, data.process()) |
|
112
|
|
|
|