osm_poi_matchmaker.dataproviders.hu_cib_bank   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 95
Duplicated Lines 12.63 %

Importance

Changes 0
Metric Value
eloc 83
dl 12
loc 95
rs 10
c 0
b 0
f 0
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_cib_bank.__init__() 12 13 1
F hu_cib_bank.process() 0 39 14
A hu_cib_bank.types() 0 19 1

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 clean_city, 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_cib_bank(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_cib_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 (8/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': 'CIB Bank', 'operator': 'CIB Bank Zrt.', 'operator:addr': '1027 Budapest, Medve u 4-14.',
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...
27
                     'bic': 'CIBHHUHB', 'ref:vatin': 'HU10136915', 'ref:vatin:hu': '10136915-4-44',
28
                     'ref:HU:company': '01 10 041004', 'brand:wikidata': 'Q839566',
29
                     'brand:wikipedia': 'hu:CIB Bank', }
30
        self.prefer_osm_postcode = prefer_osm_postcode
31
        self.name = name
32
        self.filetype = FileType.json
33
        self.filename = '{}.{}'.format(
34
            self.__class__.__name__, self.filetype.name)
35
36
    def types(self):
37
        hucibbank = {'amenity': 'bank', 'atm': 'yes',
38
                     'air_conditioning': 'yes', }
39
        hucibbank.update(self.tags)
40
        hucibatm = {'amenity': 'atm'}
41
        hucibatm.update(self.tags)
42
        data = [
43
            {'poi_code': 'hucibbank', 'poi_name': 'CIB Bank', 'poi_type': 'bank', 'poi_tags': hucibbank,
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...
44
             'poi_url_base': 'https://www.cib.hu', 'poi_search_name': '(cib bank|cib)',
45
             'poi_search_avoid_name': '(raiffeisen|otp|k&h|budapest)',
46
             'osm_search_distance_perfect': 300, 'osm_search_distance_safe': 100,
47
             'osm_search_distance_unsafe': 40},
48
            {'poi_code': 'hucibatm', 'poi_name': 'CIB Bank ATM', 'poi_type': 'atm', 'poi_tags': hucibatm,
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...
49
             'poi_url_base': 'https://www.cib.hu', 'poi_search_name': '(cib bank atm|cib atm)',
50
             'poi_search_avoid_name': '(raiffeisen|otp|k&h|budapest)',
51
             'osm_search_distance_perfect': 50, 'osm_search_distance_safe': 30,
52
             'osm_search_distance_unsafe': 10}
53
        ]
54
        return data
55
56
    def process(self):
57
        try:
58
            if self.link:
59
                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...
60
                    text = json.load(f)
61
                    data = POIDataset()
62
                    for poi_data in text['availableLocations']:
63
                        if 'locationStatus' in poi_data and poi_data['locationStatus'] == 'IN_SERVICE':
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...
64
                            if self.name == 'CIB Bank':
65
                                data.name = 'CIB Bank'
66
                                data.code = 'hucibbank'
67
                                data.public_holiday_open = False
68
                            else:
69
                                data.name = 'CIB Bank ATM'
70
                                data.code = 'hucibatm'
71
                                data.public_holiday_open = True
72
                            data.lat, data.lon = check_hu_boundary(poi_data['location']['lat'],
73
                                                                   poi_data['location']['lon'])
74
                            data.city = clean_city(poi_data['city'])
75
                            data.postcode = poi_data.get('zip').strip()
76
                            data.housenumber = poi_data['streetNo'].strip()
77
                            data.street = poi_data['streetName'].strip()
78
                            data.branch = poi_data['name']
79
                            if 'phone' in poi_data and poi_data['phone'] != '':
80
                                data.phone = clean_phone_to_str(
81
                                    poi_data['phone'])
82
                            if 'email' in poi_data and poi_data['email'] != '':
83
                                data.email = poi_data['email'].strip()
84
                            data.original = poi_data['fullAddress']
85
                            data.add()
86
                if data is None or data.lenght() < 1:
87
                    logging.warning('Resultset is empty. Skipping ...')
88
                else:
89
                    insert_poi_dataframe(self.session, data.process())
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
            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...
95