hu_cba.process()   D
last analyzed

Complexity

Conditions 13

Size

Total Lines 44
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 39
nop 1
dl 0
loc 44
rs 4.2
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like osm_poi_matchmaker.dataproviders.hu_cba.hu_cba.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_street_housenumber_better_2, clean_city, \
11
        extract_javascript_variable, clean_opening_hours_2, clean_phone_to_str
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_cba(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_cba" 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
    def constains(self):
26
        self.link = 'http://www.cba.hu/uzletlista'
27
        self.tags = {}
28
        self.tags.update(POS_HU_GEN)
29
        self.tags.update(PAY_CASH)
30
        self.filetype = FileType.html
31
        self.filename = '{}.{}'.format(
32
            self.__class__.__name__, self.filetype.name)
33
34
    def types(self):
35
        hucbacon = {'shop': 'convenience', 'brand': 'CBA', }
36
        hucbasup = {'shop': 'supermarket', 'brand': 'CBA', }
37
        huprimacon = {'shop': 'convenience', 'brand': 'Príma', }
38
        huprimasup = {'shop': 'supermarket', 'brand': 'Príma', }
39
        for i in [hucbacon, hucbasup, huprimacon, huprimasup]:
40
            i.update(self.tags)
41
        self.__types = [
42
            {'poi_code': 'hucbacon', 'poi_name': 'CBA', 'poi_type': 'shop',
43
             'poi_tags': hucbacon, 'poi_url_base': 'https://www.cba.hu', 'poi_search_name': '(cba abc|cba)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

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

Loading history...
44
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 5,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

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

Loading history...
45
             'preserve_original_name': True},
46
            {'poi_code': 'hucbasup', 'poi_name': 'CBA', 'poi_type': 'shop',
47
             'poi_tags': hucbasup, 'poi_url_base': 'https://www.cba.hu', 'poi_search_name': '(cba abc|cba)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

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

Loading history...
48
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 5,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

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

Loading history...
49
             'preserve_original_name': True},
50
            {'poi_code': 'huprimacon', 'poi_name': 'Príma', 'poi_type': 'shop',
51
             'poi_tags': huprimacon, 'poi_url_base': 'https://www.prima.hu',
52
             'poi_search_name': '(príma abc|prima abc|príma|prima)',
53
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 23,
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...
54
             'preserve_original_name': True},
55
            {'poi_code': 'huprimasup', 'poi_name': 'Príma', 'poi_type': 'shop',
56
             'poi_tags': huprimasup, 'poi_url_base': 'https://www.prima.hu',
57
             'poi_search_name': '(príma abc|prima abc|príma|prima)',
58
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 23,
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...
59
             'preserve_original_name': True},
60
        ]
61
        return self.__types
62
63
    def process(self):
64
        try:
65
            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...
66
                                        self.filetype)
67
            if soup is not None:
68
                # parse the html using beautiful soap and store in variable `soup`
69
                text = json.loads(
70
                    extract_javascript_variable(soup, 'boltok_nyers'))
71
                for poi_data in text:
72
                    # Assign: code, postcode, city, name, branch, website, original, street, housenumber, conscriptionnumber, ref, geom
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (135/100).

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

Loading history...
73
                    self.data.city = clean_city(poi_data.get('A_VAROS'))
74
                    self.data.postcode = poi_data.get('A_IRSZ').strip()
75
                    self.data.branch = poi_data.get('P_NAME').strip()
76
                    self.data.name = 'Príma' if 'Príma' in self.data.branch else 'CBA'
77
                    self.data.code = 'huprimacon' if 'Príma' in self.data.branch else 'hucbacon'
78
                    for i in range(0, 7):
79
                        self.data.day_open(i, clean_opening_hours_2(
80
                            poi_data.get('PS_OPEN_FROM_{}'.format(i + 1))) if poi_data.get(
81
                            'PS_OPEN_FROM_{}'.format(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 4 spaces).
Loading history...
82
                                i + 1)) is not None else None)
83
                        self.data.day_close(i, clean_opening_hours_2(
84
                            poi_data.get('PS_OPEN_TO_{}'.format(i + 1))) if poi_data.get(
85
                            'PS_OPEN_TO_{}'.format(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 4 spaces).
Loading history...
86
                                i + 1)) is not None else None)
87
                    self.data.original = poi_data.get('A_CIM')
88
                    self.data.lat, self.data.lon = check_hu_boundary(poi_data.get('PS_GPS_COORDS_LAT'),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
89
                                                                     poi_data.get('PS_GPS_COORDS_LNG'))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
90
                    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...
91
                        poi_data.get('A_CIM'))
92
                    if 'PS_PUBLIC_TEL' in poi_data and poi_data.get('PS_PUBLIC_TEL') != '':
93
                        self.data.phone = clean_phone_to_str(
94
                            poi_data.get('PS_PUBLIC_TEL'))
95
                    else:
96
                        self.data.phone = None
97
                    if 'PS_PUBLIC_EMAIL' in poi_data and poi_data.get('PS_PUBLIC_EMAIL') != '':
98
                        self.data.email = poi_data.get('PS_PUBLIC_EMAIL')
99
                    else:
100
                        self.data.email = None
101
                    self.data.public_holiday_open = False
102
                    self.data.add()
103
        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...
104
            logging.exception('Exception occurred')
105
106
            logging.error(e)
107