hu_obi.process()   D
last analyzed

Complexity

Conditions 12

Size

Total Lines 33
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 29
nop 1
dl 0
loc 33
rs 4.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like osm_poi_matchmaker.dataproviders.hu_obi.hu_obi.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 json
8
    from osm_poi_matchmaker.libs.soup import save_downloaded_soup
9
    from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city, clean_phone_to_str, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

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

Loading history...
10
        clean_email
11
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
12
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH
13
    from osm_poi_matchmaker.utils.data_provider import DataProvider
14
    from osm_poi_matchmaker.utils.enums import FileType
15
except ImportError as err:
16
    logging.error('Error %s import module: %s', __name__, err)
17
    logging.exception('Exception occurred')
18
19
    sys.exit(128)
20
21
22
class hu_obi(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_obi" 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...
23
24
    def constains(self):
25
        self.link = 'https://www.obi.hu/storeLocatorRest/v1/stores/getAllByCountry/hu/hu?fields=name,address,phone,services,hours,storeNumber,path,email'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (153/100).

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

Loading history...
26
        self.tags = {'shop': 'doityourself', 'brand': 'OBI', 'brand:wikidata': 'Q300518',
27
                     'brand:wikipedia': 'en:Obi (store)', 'operator': 'OBI Hungary Retail Kft.',
28
                     'operator:addr': '1097 Budapest, Könyves Kálmán körút 12-14',
29
                     'ref:vatin:hu': '13136062-2-44', 'ref:vatin': 'HU13136062',
30
                     'wheelchair': 'yes', 'air_conditioning': 'yes', }
31
        self.filetype = FileType.json
32
        self.filename = '{}.{}'.format(
33
            self.__class__.__name__, self.filetype.name)
34
35
    def types(self):
36
        huobidiy = self.tags.copy()
37
        huobidiy.update(POS_HU_GEN)
38
        huobidiy.update(PAY_CASH)
39
        self.__types = [
40
            {'poi_code': 'huobidiy', 'poi_name': 'OBI', 'poi_type': 'doityourself',
41
             'poi_tags': huobidiy, 'poi_url_base': 'https://www.obi.hu', 'poi_search_name': 'obi',
42
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200, 'osm_search_distance_unsafe': 15},
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...
43
        ]
44
        return self.__types
45
46
    def process(self):
47
        try:
48
            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...
49
                                        self.filetype)
50
            if soup is not None:
51
                text = json.loads(soup)
52
                for poi_data in text.get('stores'):
53
                    self.data.name = 'OBI'
54
                    self.data.code = 'huobidiy'
55
                    self.data.postcode = poi_data['address']['zip'].strip()
56
                    self.data.city = clean_city(poi_data['address']['city'])
57
                    self.data.original = poi_data['address']['street']
58
                    self.data.lat, self.data.lon = check_hu_boundary(poi_data['address']['lat'],
59
                                                                     poi_data['address']['lon'])
60
                    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...
61
                        poi_data['address']['street'])
62
                    if 'phone' in poi_data and poi_data.get('phone') != '':
63
                        self.data.phone = clean_phone_to_str(
64
                            poi_data.get('phone'))
65
                    if 'storeNumber' in poi_data and poi_data.get('storeNumber') != '':
66
                        self.data.ref = poi_data.get('storeNumber').strip()
67
                    if 'email' in poi_data and poi_data.get('email') != '':
68
                        self.data.email = clean_email(poi_data.get('email'))
69
                    if 'path' in poi_data and poi_data.get('path') != '':
70
                        self.data.website = poi_data.get('path')
71
                    # TODO: opening hour parser for poi_data.get('hours'), format is like:
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
72
                    #  Hétfő - Szombat: 8:00 - 20:00\nVasárnap: 08:00 - 18:00
73
                    # self.data.public_holiday_open = False
74
                    self.data.add()
75
        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...
76
            logging.exception('Exception occurred')
77
78
            logging.error(e)
79