osm_poi_matchmaker.dataproviders.hu_sber_bank   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 102
dl 0
loc 115
rs 10
c 0
b 0
f 0
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_sber_bank.constains() 0 10 1
F hu_sber_bank.process() 0 63 14
A hu_sber_bank.types() 0 18 1
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
    import os
8
    from osm_poi_matchmaker.libs.soup import save_downloaded_soup
9
    from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2
10
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
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_sber_bank(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_sber_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...
21
22
    def constains(self):
23
        self.link = 'https://www.sberbank.hu/servlet/maplocatorServlet'
24
        self.tags = {'brand': 'Sberbank', 'brand:wikidata': 'Q17379757', 'bic': 'MAVOHUHB',
25
                     'brand:wikipedia': 'en:Sberbank of Russia', 'operator': 'Sberbank Magyarország Zrt.',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

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

Loading history...
26
                     'operator:addr': '1088 Budapest, Rákóczi út 1-3.', 'brand:ru': 'Сбербанк',
27
                     'name:ru': 'Сбербанк', 'ref:vatin': 'HU10776999', 'ref:vatin:hu': '10776999-2-44',
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...
28
                     'ref:HU:company': '01 10 041720'}
29
        self.filetype = FileType.json
30
        self.filename = '{}.{}'.format(
31
            self.__class__.__name__, self.filetype.name)
32
33
    def types(self):
34
        husberbank = {'amenity': 'bank',
35
                      'atm': 'yes', 'air_conditioning': 'yes'}
36
        husberbank.update(self.tags)
37
        husberatm = {'amenity': 'atm'}
38
        husberatm.update(self.tags)
39
        self.__types = [
40
            {'poi_code': 'husberbank', 'poi_name': 'Sberbank', 'poi_type': 'bank',
41
             'poi_tags': husberbank, 'poi_url_base': 'https://www.sberbank.hu', 'poi_search_name': '(sber|sberbank)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

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

Loading history...
42
             # Note: Volksbank is Sberbank
43
             # https://www.sberbank.at/press-releases/sberbank-completes-acquisition-volksbank-international
44
             'poi_search_avoid_name': '(erste|raiffeisen)',
45
             'osm_search_distance_perfect': 300, 'osm_search_distance_safe': 100, 'osm_search_distance_unsafe': 40},
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...
46
            {'poi_code': 'husberatm', 'poi_name': 'Sberbank ATM', 'poi_type': 'atm',
47
             'poi_tags': husberatm, 'poi_url_base': 'https://www.sberbank.hu', 'poi_search_name': '(sber|sberbank)',
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...
48
             'osm_search_distance_perfect': 50, 'osm_search_distance_safe': 30, 'osm_search_distance_unsafe': 10},
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...
49
        ]
50
        return self.__types
51
52
    def process(self):
53
        try:
0 ignored issues
show
unused-code introduced by
Too many nested blocks (6/5)
Loading history...
54
            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...
55
                                        self.filetype)
56
            if soup is not None:
57
                text = json.loads(soup)
58
                for poi_data in text['atmList']:
59
                    self.data.name = 'Sberbank ATM'
60
                    self.data.code = 'husberatm'
61
                    self.data.public_holiday_open = True if poi_data.get(
0 ignored issues
show
Unused Code introduced by
The if expression can be replaced with 'test'
Loading history...
62
                        'atmNonstop') is True else False
63
                    self.data.postcode = poi_data.get('address')['zipCode']
64
                    ctmp = poi_data.get('address')['city']
65
                    self.data.city = ctmp if 'kerület' not in ctmp else poi_data.get('address')[
66
                        'county']
67
                    self.data.lat, self.data.lon = check_hu_boundary(poi_data.get('address')['coordinateX'],
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...
68
                                                                     poi_data.get('address')['coordinateY'])
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...
69
                    street_tmp = '{} {}'.format(poi_data.get('address')['street'],
70
                                                poi_data.get('address')['houseNumber'].split('.')[0])
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...
71
                    self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
72
                        extract_street_housenumber_better_2(street_tmp)
73
                    self.data.original = street_tmp
74
                    self.data.add()
75
                for poi_data in text['branchList']:
76
                    self.data.name = 'Sberbank'
77
                    self.data.code = 'husberbank'
78
                    self.data.public_holiday_open = False
79
                    self.data.postcode = poi_data.get('address')['zipCode']
80
                    ctmp = poi_data.get('address')['city']
81
                    self.data.city = ctmp if 'kerület' not in ctmp else poi_data.get('address')[
82
                        'county']
83
                    self.data.lat, self.data.lon = check_hu_boundary(poi_data.get('address')['coordinateX'],
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...
84
                                                                     poi_data.get('address')['coordinateY'])
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...
85
                    street_tmp = '{} {}'.format(poi_data.get('address')['street'],
86
                                                poi_data.get('address')['houseNumber'].split('.')[0])
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...
87
                    self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
88
                        extract_street_housenumber_better_2(street_tmp)
89
                    self.data.original = street_tmp
90
                    self.data.email = poi_data.get('emailAppointment')
91
                    self.data.phone = poi_data.get('phone'.split('/')[0])
92
                    for i, opening in enumerate(poi_data.get('openTime')):
93
                        if opening is not None and opening != '':
94
                            try:
95
                                oh = opening.get('from') if opening.get(
0 ignored issues
show
Coding Style Naming introduced by
Variable name "oh" 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...
96
                                    'from') != '' else None
97
                                self.data.day_open(i, oh)
98
                                ch = opening.get('to') if opening.get(
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ch" 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...
99
                                    'to') != '' else None
100
                                self.data.day_close(i, ch)
101
                            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...
102
                                logging.info(opening)
103
                                logging.exception('Exception occurred')
104
105
                                logging.error(e)
106
                                continue
107
                        else:
108
                            logging.debug(
109
                                'There is no opening hours on day: {}.'.format(i))
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
110
                    self.data.add()
111
        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...
112
            logging.exception('Exception occurred')
113
114
            logging.error(e)
115