osm_poi_matchmaker.dataproviders.hu_mobil_petrol   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 82
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 14

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_mobil_petrol.constains() 0 9 1
D hu_mobil_petrol.process() 0 47 12
A hu_mobil_petrol.types() 0 10 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
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, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_mobil_petrol" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing class docstring
Loading history...
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',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
30
                     'operator:addr': '1095 Budapest, Ipar utca 2.', 'operator': 'MPH Power Zrt.', 'fuel:diesel': 'yes',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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:
0 ignored issues
show
unused-code introduced by
Too many nested blocks (6/5)
Loading history...
49
            soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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(
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (128/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
Variable name "e" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
91
            logging.exception('Exception occurred')
92
93
            logging.error(e)
94