hu_mol.process()   C
last analyzed

Complexity

Conditions 10

Size

Total Lines 41
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 39
nop 1
dl 0
loc 41
rs 5.9999
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like osm_poi_matchmaker.dataproviders.hu_mol.hu_mol.process() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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
10
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
11
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH
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
POST_DATA = {'country': 'Magyarország', 'lat': '47.162494',
21
             'lng': '19.503304100000037', 'radius': 20}
22
23
24
class hu_mol(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_mol" 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 View Code Duplication
    def constains(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
        self.link = 'http://toltoallomaskereso.mol.hu/hu/portlet/routing/along_latlng.json'
28
        self.fuel = {'amenity': 'fuel', 'fuel:diesel': 'yes', 'fuel:octane_95': 'yes', 'air_conditioning': 'yes'}
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...
29
        self.tags = {'brand': 'MOL', 'operator': 'MOL Nyrt.',
30
                     'operator:addr': '1117 Budapest, Október huszonharmadika utca 18.',
31
                     'ref:vatin:hu': '10625790-4-44',
32
                     'contact:facebook': 'https://www.facebook.com/mol.magyarorszag/',
33
                     'contact:youtube': 'https://www.youtube.com/user/molgrouptv',
34
                     'contact:instagram': 'https://www.instagram.com/mol.magyarorszag/',
35
                     'brand:wikipedia': 'hu:MOL Magyar Olaj- és Gázipari Nyrt.', 'brand:wikidata': 'Q549181',
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...
36
                     'ref:HU:company': '01-10-041683'}
37
        self.waterway_fuel = {'waterway': 'fuel'}
38
        self.filetype = FileType.json
39
        self.filename = '{}.{}'.format(
40
            self.__class__.__name__, self.filetype.name)
41
42
    def types(self):
43
        humolfu = self.tags.copy()
44
        humolfu.update(self.fuel)
45
        humolfu.update(POS_HU_GEN)
46
        humolfu.update(PAY_CASH)
47
        humolwfu = self.tags.copy()
48
        humolwfu.update(self.waterway_fuel)
49
        humolwfu.update(POS_HU_GEN)
50
        humolwfu.update(PAY_CASH)
51
        self.__types = [
52
            {'poi_code': 'humolfu', 'poi_name': 'MOL', 'poi_type': 'fuel',
53
             'poi_tags': humolfu, 'poi_url_base': 'https://www.mol.hu', 'poi_search_name': 'mol',
54
             'osm_search_distance_perfect': 2000,
55
             'osm_search_distance_safe': 300, 'osm_search_distance_unsafe': 60},
56
            {'poi_code': 'humolwfu', 'poi_name': 'MOL', 'poi_type': 'fuel',
57
             'poi_tags': humolwfu, 'poi_url_base': 'https://www.mol.hu', 'poi_search_name': 'mol',
58
             'osm_search_distance_perfect': 2000,
59
             'osm_search_distance_safe': 800, 'osm_search_distance_unsafe': 300}, ]
60
        return self.__types
61
62
    def process(self):
63
        try:
64
            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...
65
                                        self.filetype, POST_DATA)
66
            if soup is not None:
67
                text = json.loads(soup)
68
                for poi_data in text:
69
                    self.data.name = 'MOL'
70
                    if " Sziget " in poi_data.get('name'):
71
                        self.data.code = 'humolwfu'
72
                    else:
73
                        self.data.code = 'humolfu'
74
                    self.data.postcode = poi_data.get('postcode').strip()
75
                    self.data.city = clean_city(poi_data['city'])
76
                    self.data.original = poi_data['address']
77
                    self.data.lat, self.data.lon = check_hu_boundary(
78
                        poi_data['lat'], poi_data['lng'])
79
                    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...
80
                        poi_data['address'])
81
                    self.data.public_holiday_open = True
82
                    self.data.truck = True if 'kamion_parkolo' in poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
83
                        'servicesin') else False
84
                    self.data.food = True if 'fresh_corner' in poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
85
                        'servicesin') else False
86
                    self.data.rent_lpg_bottles = True if 'pb' in poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
87
                        'servicesin') else False
88
                    self.data.fuel_adblue = True if 'adblue' in poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
89
                        'servicesin') else False
90
                    self.data.fuel_lpg = True if 'lpg' in poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
91
                        'servicesin') else False
92
                    self.data.fuel_octane_95 = True
93
                    self.data.fuel_diesel = True
94
                    self.data.fuel_octane_100 = True
95
                    self.data.fuel_diesel_gtl = True
96
                    self.data.compressed_air = True
97
                    self.data.public_holiday_open = False
98
                    self.data.add()
99
        except Exception as e:
0 ignored issues
show
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...
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...
100
            logging.exception('Exception occurred')
101
102
            logging.error(e)
103