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_opening_hours, \ |
|
|
|
|
10
|
|
|
clean_phone_to_str |
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_oil(DataProvider): |
|
|
|
|
23
|
|
|
|
24
|
|
|
def constains(self): |
25
|
|
|
self.link = 'http://www.oil-benzinkutak.hu/wp-admin/admin-ajax.php?action=store_search&lat=47.162494&lng=19.5033041&max_results=1&search_radius=50&autoload=1' |
|
|
|
|
26
|
|
|
self.tags = {'amenity': 'fuel', 'name': 'OIL!', 'brand': 'OIL!', 'fuel:diesel': 'yes', |
27
|
|
|
'fuel:octane_95': 'yes', 'brand:wikidata': 'Q2007561', |
28
|
|
|
'brand:wikipedia': 'OIL! Tankstellen', 'operator': 'Mabanaft Hungary Kft.', |
29
|
|
|
'operator:addr': '1016 Budapest, Mészáros utca 58/B', |
30
|
|
|
'ref:vatin:hu': '12700226-2-44', 'ref:vatin': 'HU12700226', |
31
|
|
|
'ref:HU:company': '01-09-699184', |
32
|
|
|
'contact:facebook': 'https://www.facebook.com/OILHungary/', } |
33
|
|
|
self.filetype = FileType.json |
34
|
|
|
self.filename = '{}.{}'.format(self.__class__.__name__, self.filetype.name) |
35
|
|
|
|
36
|
|
|
def types(self): |
37
|
|
|
huoilfu = self.tags.copy() |
38
|
|
|
huoilfu.update(POS_HU_GEN) |
39
|
|
|
huoilfu.update(PAY_CASH) |
40
|
|
|
self.__types = [ |
41
|
|
|
{'poi_code': 'huoilfu', 'poi_name': 'OIL!', 'poi_type': 'fuel', |
42
|
|
|
'poi_tags': huoilfu, 'poi_url_base': 'https://www.oil-benzinkutak.hu', 'poi_search_name': '(oil|oil!|oil benzinkutak|oil-benzinkutak)', |
|
|
|
|
43
|
|
|
'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 450, |
44
|
|
|
'osm_search_distance_unsafe': 60}, |
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: |
55
|
|
|
try: |
56
|
|
|
self.data.name = 'OIL!' |
57
|
|
|
self.data.code = 'huoilfu' |
58
|
|
|
if poi_data.get('zip') is not None and poi_data.get('zip') != '': |
59
|
|
|
self.data.postcode = poi_data.get('zip').strip() |
60
|
|
|
if poi_data.get('city') is not None and poi_data.get('city') != '': |
61
|
|
|
self.data.city = clean_city(poi_data.get('city')) |
62
|
|
|
self.data.lat, self.data.lon = check_hu_boundary( |
63
|
|
|
poi_data.get('lat'), poi_data.get('lng')) |
64
|
|
|
if poi_data.get('address') is not None and poi_data.get('address') != '': |
65
|
|
|
self.data.original = poi_data.get('address') |
66
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
|
|
|
|
67
|
|
|
extract_street_housenumber_better_2( |
68
|
|
|
poi_data.get('address')) |
69
|
|
|
if poi_data.get('phone') is not None and poi_data.get('phone') != '': |
70
|
|
|
self.data.phone = clean_phone_to_str( |
71
|
|
|
poi_data.get('phone')) |
72
|
|
|
self.data.fuel_octane_95 = True |
73
|
|
|
self.data.fuel_diesel = True |
74
|
|
|
if poi_data.get('id') is not None and poi_data.get('id') != '': |
75
|
|
|
self.data.ref = poi_data.get('id').strip() |
76
|
|
|
if poi_data.get('url') is not None and poi_data.get('url') != '': |
77
|
|
|
self.data.website = poi_data.get('url').strip() |
78
|
|
|
else: |
79
|
|
|
self.data.website = 'https://www.oil-benzinkutak.hu' |
80
|
|
|
if poi_data.get('store') is not None and poi_data.get('store') != '': |
81
|
|
|
tmp = poi_data.get('store').split(' ', 1) |
82
|
|
|
self.data.branch = tmp[1].strip().capitalize() |
83
|
|
|
self.data.add() |
84
|
|
|
except Exception as e: |
|
|
|
|
85
|
|
|
logging.error(e) |
86
|
|
|
logging.error(poi_data) |
87
|
|
|
logging.exception('Exception occurred') |
88
|
|
|
|
89
|
|
|
except Exception as e: |
|
|
|
|
90
|
|
|
logging.error(e) |
91
|
|
|
logging.exception('Exception occurred') |
92
|
|
|
|