1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
from builtins import Exception, ImportError, range |
5
|
|
|
import logging |
6
|
|
|
import sys |
7
|
|
|
import json |
8
|
|
|
import os |
9
|
|
|
import re |
|
|
|
|
10
|
|
|
from osm_poi_matchmaker.libs.soup import save_downloaded_soup |
11
|
|
|
from osm_poi_matchmaker.libs.address import clean_city, extract_street_housenumber_better_2, clean_phone_to_str, \ |
|
|
|
|
12
|
|
|
extract_javascript_variable |
13
|
|
|
from osm_poi_matchmaker.libs.geo import check_hu_boundary |
14
|
|
|
from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH |
15
|
|
|
from osm_poi_matchmaker.utils.data_provider import DataProvider |
16
|
|
|
from osm_poi_matchmaker.utils.enums import FileType |
17
|
|
|
except ImportError as err: |
18
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
19
|
|
|
logging.exception('Exception occurred') |
20
|
|
|
|
21
|
|
|
sys.exit(128) |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class hu_mobil_petrol(DataProvider): |
|
|
|
|
25
|
|
|
|
26
|
|
|
def constains(self): |
27
|
|
|
self.link = 'http://www.mpetrol.hu/' |
28
|
|
|
self.tags = {'amenity': 'fuel', 'brand': 'Mobil Petrol', 'contact:email': '[email protected]', |
29
|
|
|
'contact:facebook': 'https://www.facebook.com/mpetrolofficial/', 'name': 'Mobil Petrol', |
|
|
|
|
30
|
|
|
'operator:addr': '1095 Budapest, Ipar utca 2.', 'operator': 'MPH Power Zrt.', 'fuel:diesel': 'yes', |
|
|
|
|
31
|
|
|
'fuel:octane_95': 'yes'} |
32
|
|
|
self.filetype = FileType.html |
33
|
|
|
self.filename = '{}.{}'.format( |
34
|
|
|
self.__class__.__name__, self.filetype.name) |
35
|
|
|
|
36
|
|
|
def types(self): |
37
|
|
|
humobpefu = self.tags.copy() |
38
|
|
|
humobpefu.update(POS_HU_GEN) |
39
|
|
|
humobpefu.update(PAY_CASH) |
40
|
|
|
self.__types = [ |
41
|
|
|
{'poi_code': 'humobpefu', 'poi_name': 'Mobil Petrol', 'poi_type': 'fuel', |
42
|
|
|
'poi_tags': humobpefu, 'poi_url_base': 'http://mpetrol.hu/', |
43
|
|
|
'poi_search_name': '(mobil metrol|shell)'}, |
44
|
|
|
] |
45
|
|
|
return self.__types |
46
|
|
|
|
47
|
|
|
def process(self): |
48
|
|
|
try: |
|
|
|
|
49
|
|
|
soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
|
|
|
|
50
|
|
|
self.filetype) |
51
|
|
|
if soup is not None: |
52
|
|
|
# parse the html using beautiful soap and store in variable `soup` |
53
|
|
|
text = json.loads( |
54
|
|
|
extract_javascript_variable(soup, 'totem_stations')) |
55
|
|
|
for poi_data in text.values(): |
56
|
|
|
self.data.name = 'Mobil Petrol' |
57
|
|
|
self.data.code = 'humobpefu' |
58
|
|
|
self.data.website = poi_data.get('description') |
59
|
|
|
self.data.city = clean_city(poi_data.get('city')) |
60
|
|
|
self.data.original = poi_data.get('address') |
61
|
|
|
self.data.lat, self.data.lon = check_hu_boundary(poi_data['location']['lat'], |
62
|
|
|
poi_data['location']['lng']) |
63
|
|
|
self.data.postcode = None |
64
|
|
|
self.data.street, self.data.housenumber, self.data.conscriptionnumber = extract_street_housenumber_better_2( |
|
|
|
|
65
|
|
|
poi_data.get('address')) |
66
|
|
|
self.data.phone = clean_phone_to_str(poi_data.get('phone')) |
67
|
|
|
self.data.public_holiday_open = False |
68
|
|
|
if '0-24' in poi_data.get('services'): |
69
|
|
|
self.data.nonstop = True |
70
|
|
|
self.data.public_holiday_open = True |
71
|
|
|
else: |
72
|
|
|
if '6-22' in poi_data.get('services'): |
73
|
|
|
open_from = '06:00' |
74
|
|
|
open_to = '22:00' |
75
|
|
|
elif '6-21' in poi_data.get('services'): |
76
|
|
|
open_from = '06:00' |
77
|
|
|
open_to = '21:00' |
78
|
|
|
elif '5-22' in poi_data.get('services'): |
79
|
|
|
open_from = '05:00' |
80
|
|
|
open_to = '22:00' |
81
|
|
|
elif '6-18' in poi_data.get('services'): |
82
|
|
|
open_from = '06:00' |
83
|
|
|
open_to = '18:00' |
84
|
|
|
if 'open_from' in locals() and 'open_to' in locals(): |
85
|
|
|
for i in range(0, 7): |
86
|
|
|
self.data.day_open(i, open_from) |
87
|
|
|
self.data.day_close(i, open_to) |
88
|
|
|
self.data.public_holiday_open = False |
89
|
|
|
self.data.add() |
90
|
|
|
except Exception as e: |
|
|
|
|
91
|
|
|
logging.exception('Exception occurred') |
92
|
|
|
|
93
|
|
|
logging.error(e) |
94
|
|
|
|