osm_poi_matchmaker.dataproviders.hu_kh_bank   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 98
Duplicated Lines 11.22 %

Importance

Changes 0
Metric Value
eloc 85
dl 11
loc 98
rs 10
c 0
b 0
f 0
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_kh_bank.types() 0 18 1
A hu_kh_bank.__init__() 11 12 1
F hu_kh_bank.process() 0 44 14

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 json
7
    from osm_poi_matchmaker.dao.data_handlers import insert_poi_dataframe
8
    from osm_poi_matchmaker.libs.address import extract_all_address, clean_phone_to_str
9
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
10
    from osm_poi_matchmaker.libs.poi_dataset import POIDataset
11
    from osm_poi_matchmaker.utils.data_provider import DataProvider
12
    from osm_poi_matchmaker.utils.enums import FileType
13
except ImportError as err:
14
    logging.error('Error %s import module: %s', __name__, err)
15
    logging.exception('Exception occurred')
16
17
    sys.exit(128)
18
19
20
class hu_kh_bank(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_kh_bank" 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...
best-practice introduced by
Too many instance attributes (9/7)
Loading history...
21
22 View Code Duplication
    def __init__(self, session, download_cache, prefer_osm_postcode, link, name):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Bug introduced by
The __init__ method of the super-class DataProvider is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
best-practice introduced by
Too many arguments (6/5)
Loading history...
23
        self.session = session
24
        self.download_cache = download_cache
25
        self.link = link
26
        self.tags = {'brand': 'K&H', 'operator': 'K&H Bank Zrt.',
27
                     'operator:addr': '1095 Budapest, Lechner Ödön fasor 9.', 'bic': 'OKHBHUHB',
28
                     'ref:vatin': 'HU10195664', 'ref:vatin:hu': '10195664-4-44', 'ref:HU:company': '01 10 041043', }
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...
29
        self.prefer_osm_postcode = prefer_osm_postcode
30
        self.name = name
31
        self.filetype = FileType.json
32
        self.filename = '{}.{}'.format(
33
            self.__class__.__name__, self.filetype.name)
34
35
    def types(self):
36
        hukhbank = {'amenity': 'bank', 'atm': 'yes',
37
                    'air_conditioning': 'yes', }
38
        hukhbank.update(self.tags)
39
        hukhatm = {'amenity': 'atm'}
40
        hukhatm.update(self.tags)
41
        self.__types = [
42
            {'poi_code': 'hukhbank', 'poi_name': 'K&H Bank', 'poi_type': 'bank',
43
             'poi_tags': hukhbank, 'poi_url_base': 'https://www.kh.hu',
44
             'poi_search_name': '(kh bank|k&h bank|k&h|kh)', 'osm_search_distance_perfect': 2000,
45
             'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 4},
46
            {'poi_code': 'hukhatm', 'poi_name': 'K&H Bank ATM', 'poi_type': 'atm',
47
             'poi_tags': hukhatm, 'poi_url_base': 'https://www.kh.hu',
48
             'poi_search_name': '(kh bank atm|k&h bank atm|k&h atm|kh atm)',
49
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 80,
50
             'osm_search_distance_unsafe': 3},
51
        ]
52
        return self.__types
53
54
    def process(self):
55
        try:
56
            if self.link:
57
                with open(self.link, 'r') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
58
                    text = json.load(f)
59
                    data = POIDataset()
60
                    for poi_data in text['results']:
61
                        first_element = next(iter(poi_data))
62
                        if self.name == 'K&H Bank':
63
                            data.name = 'K&H Bank'
64
                            data.code = 'hukhbank'
65
                            data.public_holiday_open = False
66
                        elif self.name == 'K&H Bank ATM':
67
                            data.name = 'K&H Bank ATM'
68
                            data.code = 'hukhatm'
69
                            data.public_holiday_open = True
70
                        if data.code == 'hukhatm':
71
                            data.nonstop = True
72
                        else:
73
                            data.nonstop = False
74
                        data.lat, data.lon = check_hu_boundary(poi_data.get(first_element)['latitude'],
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...
75
                                                               poi_data.get(first_element)['longitude'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
76
                        if poi_data.get(first_element)['address'] is not None and \
77
                                poi_data.get(first_element)['address'] != '':
78
                            data.postcode, data.city, data.street, data.housenumber, data.conscriptionnumber = \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

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

Loading history...
79
                                extract_all_address(
80
                                    poi_data.get(first_element)['address'])
81
                            data.original = poi_data.get(
82
                                first_element)['address']
83
                        if poi_data.get('phoneNumber') is not None and poi_data.get('phoneNumber') != '':
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
84
                            data.phone = clean_phone_to_str(
85
                                poi_data.get('phoneNumber'))
86
                        else:
87
                            data.phone = None
88
                        data.add()
89
                    if data is None or data.lenght() < 1:
90
                        logging.warning('Resultset is empty. Skipping ...')
91
                    else:
92
                        insert_poi_dataframe(self.session, data.process())
93
        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...
94
            logging.exception('Exception occurred')
95
96
            logging.error(e)
97
            logging.error(poi_data)
0 ignored issues
show
introduced by
The variable poi_data does not seem to be defined for all execution paths.
Loading history...
98