hu_pepco.process()   C
last analyzed

Complexity

Conditions 10

Size

Total Lines 47
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 35
nop 1
dl 0
loc 47
rs 5.9999
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like osm_poi_matchmaker.dataproviders.hu_pepco.hu_pepco.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 (115/100).

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

Loading history...
10
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
11
    from osm_poi_matchmaker.libs.osm import query_osm_city_name
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_pepco(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_pepco" 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://pepco.hu/uzleteink/uzletkereso/?type=1002&tx_pepco_mapplugin[action]=view&tx_pepco_mapplugin[controller]=Map&tx_pepco_mapplugin[loadall]=true'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (171/100).

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

Loading history...
26
        self.tags = {'shop': 'clothes', 'brand': 'Pepco', 'brand:wikidata': 'Q11815580',
27
                     'brand:wikipedia': 'pl:Pepco', 'contact:facebook': 'https://www.facebook.com/pepcohu/',
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...
28
                     'contact:website': 'https://pepco.hu/',
29
                     'contact:linkedin': 'https://www.linkedin.com/company/pepco-poland',
30
                     'contact:phone': '+36 1 701 0424', 'contact:email': '[email protected]',
31
                     'operator': 'Pepkor Hungary Kft.', 'operator:addr': '1138 Budapest, Váci út 187.'}
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...
32
        self.filetype = FileType.json
33
        self.filename = '{}.{}'.format(
34
            self.__class__.__name__, self.filetype.name)
35
36
    def types(self):
37
        hupepcoclo = self.tags.copy()
38
        hupepcoclo.update(POS_HU_GEN)
39
        hupepcoclo.update(PAY_CASH)
40
        self.__types = [
41
            {'poi_code': 'hupepcoclo', 'poi_name': 'Pepco', 'poi_type': 'clothes',
42
             'poi_tags': hupepcoclo, 'poi_url_base': 'https://pepco.hu', 'poi_search_name': 'pepco',
43
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200,
44
             'osm_search_distance_unsafe': 5},
45
        ]
46
        return self.__types
47
48
    def process(self):
49
        try:
50
            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...
51
                                        self.filetype)
52
            if soup is not None:
53
                text = json.loads(soup)
54
                for poi_data in text['data']:
55
                    '''
56
                    The Pepco dataset contains all European data. Since the program cannot handle POIs outside Hungary (so far)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (127/100).

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

Loading history...
57
                    this will limit only for Hungarian POIs
58
                    In fact this depends on OSM extract but currently we use only Hungarian OSM extract
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...
59
                    Select only Hungarian POIs
60
                    '''
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
61
                    if 'city' in poi_data and (poi_data['city'] == '' or
0 ignored issues
show
Unused Code introduced by
Unnecessary "elif" after "continue"
Loading history...
62
                                               query_osm_city_name(self.session, poi_data['city']) is None):
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...
63
                        continue
64
                    elif 'city' in poi_data:
65
                        self.data.city = clean_city(poi_data['city'])
66
                    else:
67
                        continue
68
                    self.data.name = 'Pepco'
69
                    self.data.code = 'hupepcoclo'
70
                    # 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...
71
                    self.data.lat, self.data.lon = \
72
                        check_hu_boundary(
73
                            poi_data['coordinates']['lat'], poi_data['coordinates']['lng'])
74
                    self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
75
                        extract_street_housenumber_better_2(
76
                            poi_data.get('streetAddress'))
77
                    self.data.original = poi_data.get('streetAddress')
78
                    self.data.postcode = poi_data.get('postalCode')
79
                    # self.data.city = query_osm_city_name_gpd(self.session, self.data.lat, self.data.lon)
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...
80
                    # Assign opening_hours
81
                    opening = poi_data['openingHours']
82
                    for i in range(0, 7):
83
                        if i in opening:
84
                            self.data.day_open(i, opening[i]['from'])
85
                            self.data.day_close(i, opening[i]['to'])
86
                    # Assign additional informations
87
                    self.data.phone = clean_phone_to_str(
88
                        poi_data.get('phoneNumber'))
89
                    self.data.public_holiday_open = False
90
                    self.data.add()
91
        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...
92
            logging.exception('Exception occurred')
93
94
            logging.error(logging.error(e))
95