hu_avia.process()   F
last analyzed

Complexity

Conditions 23

Size

Total Lines 58
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 23
eloc 54
nop 1
dl 0
loc 58
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like osm_poi_matchmaker.dataproviders.hu_avia.hu_avia.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 re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
8
    import json
9
    from osm_poi_matchmaker.libs.soup import save_downloaded_soup
10
    from osm_poi_matchmaker.libs.address import extract_all_address, extract_javascript_variable, clean_phone_to_str, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
11
        clean_email
12
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
13
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH
14
    from osm_poi_matchmaker.utils.data_provider import DataProvider
15
    from osm_poi_matchmaker.utils.enums import FileType
16
except ImportError as err:
17
    logging.error('Error %s import module: %s', __name__, err)
18
    logging.exception('Exception occurred')
19
20
    sys.exit(128)
21
22
23
class hu_avia(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_avia" 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...
24
25 View Code Duplication
    def constains(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
26
        self.link = 'https://www.avia.hu/kapcsolat/toltoallomasok'
27
        self.tags = {'brand': 'Avia', 'operator': 'AVIA Hungária Kft.', 'fuel:diesel': 'yes',
28
                     'fuel:octane_95': 'yes', 'contact:email': '[email protected]',
29
                     'contact:facebook': 'https://www.facebook.com/AVIAHungary',
30
                     'contact:youtube': 'https://www.youtube.com/channel/UCjvjkjf2RgmKBuTnKSXk-Rg', }
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

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

Loading history...
31
        self.tags.update(POS_HU_GEN)
32
        self.tags.update(PAY_CASH)
33
        self.filetype = FileType.html
34
        self.filename = '{}.{}'.format(
35
            self.__class__.__name__, self.filetype.name)
36
37
    def types(self):
38
        huaviafu = {'amenity': 'fuel'}
39
        huaviafu.update(self.tags)
40
        self.__types = [
41
            {'poi_code': 'huaviafu', 'poi_name': 'Avia', 'poi_type': 'fuel', 'poi_tags': huaviafu,
42
             'poi_url_base': 'https://www.avia.hu', 'poi_search_name': 'avia',
43
             'osm_search_distance_perfect': 30000,
44
             'osm_search_distance_safe': 800, 'osm_search_distance_unsafe': 110},
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),
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...
51
                                        self.filetype)
52
            if soup is not None:
53
                # parse the html using beautiful soap and store in variable `soup`
54
                text = json.loads(extract_javascript_variable(
55
                    soup, 'markers', True), strict=False)
56
                for poi_data in text:
57
                    self.data.name = 'Avia'
58
                    self.data.code = 'huaviafu'
59
                    if self.data.city is None:
60
                        self.data.city = poi_data['title']
61
                    self.data.ref = poi_data['kutid'] if poi_data['kutid'] is not None and poi_data['kutid'] != '' \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

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

Loading history...
62
                        else None
63
                    self.data.lat, self.data.lon = check_hu_boundary(
64
                        poi_data['lat'], poi_data['lng'])
65
                    if poi_data['cim'] is not None and poi_data['cim'] != '':
66
                        self.data.postcode, self.data.city, self.data.street, self.data.housenumber, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
67
                            self.data.conscriptionnumber = extract_all_address(
68
                                poi_data['cim'])
69
                    self.data.website = '/toltoallomas/?id={}'.format(str(poi_data['kutid'])) \
70
                        if poi_data['kutid'] is not None and poi_data['kutid'] != '' else None
71
                    self.data.original = poi_data['cim']
72
                    if 'tel' in poi_data and poi_data['tel'] != '':
73
                        self.data.phone = clean_phone_to_str(poi_data['tel'])
74
                    else:
75
                        self.data.phone = None
76
                    if 'email' in poi_data and poi_data['email'] != '':
77
                        self.data.email = clean_email(poi_data['email'])
78
                    else:
79
                        self.data.email = None
80
                    self.data.public_holiday_open = False
81
                    self.data.fuel_octane_95 = True if poi_data.get('b95') == '1' or poi_data.get('b95g') == '1' \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

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

Loading history...
Unused Code introduced by
The if expression can be replaced with 'bool(test)'
Loading history...
82
                        else False
83
                    self.data.fuel_diesel = True if poi_data.get('dies') == '1' or poi_data.get('gdies') == '1' \
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...
Unused Code introduced by
The if expression can be replaced with 'bool(test)'
Loading history...
84
                        else False
85
                    self.data.fuel_octane_98 = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
86
                        'b98') == '1' else False
87
                    self.data.fuel_lpg = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
88
                        'lpg') == '1' else False
89
                    self.data.fuel_e85 = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
90
                        'e85') == '1' else False
91
                    self.data.rent_lpg_bottles = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
92
                        'pgaz') == '1' else False
93
                    self.data.compressed_air = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
94
                        'komp') == '1' else False
95
                    self.data.restaurant = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
96
                        'etterem') == '1' else False
97
                    self.data.food = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
98
                        'bufe') == '1' else False
99
                    self.data.truck = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
100
                        'kpark') == '1' else False
101
                    self.data.add()
102
        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...
103
            logging.exception('Exception occurred')
104
105
            logging.error(e)
106