osm_poi_matchmaker.dataproviders.hu_spar   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 97
dl 0
loc 110
rs 10
c 0
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_spar.constains() 0 13 1
A hu_spar.types() 0 25 1
C hu_spar.process() 0 44 9
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 re
8
    import json
9
    from osm_poi_matchmaker.libs.soup import save_downloaded_soup
10
    from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city
11
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
12
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_OTP, 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
PATTERN_SPAR_REF = re.compile('\((.*?)\)')
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \( was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \) was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
22
23
24
class hu_spar(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_spar" 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...
25
26
    def constains(self):
27
        self.link = 'https://www.spar.hu/uzletek/_jcr_content.stores.v2'
28
        self.tags = {'operator': 'SPAR Magyarország Kereskedelmi Kft.', 'brand': 'Spar',
29
                     'brand:wikipedia': 'hu:Spar', 'brand:wikidata': 'Q610492',
30
                     'contact:email': '[email protected]',
31
                     'phone': '+36208237727', 'contact:facebook': 'https://www.facebook.com/sparmagyarorszag',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
32
                     'contact:youtube': 'https://www.youtube.com/channel/UC9tu8COHiy4WkeTIN1k_Y8A',
33
                     'contact:instagram': 'https://www.instagram.com/sparmagyarorszag'}
34
        self.tags.update(POS_OTP)
35
        self.tags.update(PAY_CASH)
36
        self.filetype = FileType.json
37
        self.filename = '{}.{}'.format(
38
            self.__class__.__name__, self.filetype.name)
39
40
    def types(self):
41
        husparecon = {'shop': 'convenience'}
42
        husparecon.update(self.tags)
43
        husparisup = {'shop': 'supermarket'}
44
        husparisup.update(self.tags)
45
        husparsup = {'shop': 'supermarket'}
46
        husparsup.update(self.tags)
47
        huspardcon = {'shop': 'convenience'}
48
        huspardcon.update(self.tags)
49
        self.__types = [
50
            {'poi_code': 'husparecon', 'poi_name': 'Spar Expressz', 'poi_type': 'shop',
51
             'poi_tags': husparecon, 'poi_url_base': 'https://www.spar.hu',
52
             'poi_search_name': '(spar|spar express|spar expressz)',
53
             '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...
54
            {'poi_code': 'husparisup', 'poi_name': 'Interspar', 'poi_type': 'shop',
55
             'poi_tags': husparisup, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|interspar)',
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...
56
             '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...
57
            {'poi_code': 'husparsup', 'poi_name': 'Spar', 'poi_type': 'shop',
58
             'poi_tags': husparsup, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|spar supermarket)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

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

Loading history...
59
             '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...
60
            {'poi_code': 'huspardcon', 'poi_name': 'DeSpar', 'poi_type': 'shop',
61
             'poi_tags': huspardcon, 'poi_url_base': 'https://www.spar.hu', 'poi_search_name': '(spar|despar)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

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

Loading history...
62
             '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...
63
        ]
64
        return self.__types
65
66
    def process(self):
67
        try:
68
            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...
69
                                        self.filetype)
70
            if soup is not None:
71
                text = json.loads(soup)
72
                for poi_data in text:
73
                    # 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...
74
                    if 'xpres' in poi_data['name']:
75
                        self.data.name = 'Spar Expressz'
76
                        self.data.code = 'husparecon'
77
                    elif 'INTER' in poi_data['name']:
78
                        self.data.name = 'Interspar'
79
                        self.data.code = 'husparisup'
80
                    elif 'market' in poi_data['name']:
81
                        self.data.name = 'Spar'
82
                        self.data.code = 'husparsup'
83
                    elif 'DESPAR' in poi_data['name']:
84
                        self.data.name = 'DeSpar'
85
                        self.data.code = 'huspardcon'
86
                    else:
87
                        self.data.name = 'Spar'
88
                        self.data.code = 'husparsup'
89
                    poi_data['name'] = poi_data['name'].replace(
90
                        'INTERSPAR', 'Interspar')
91
                    poi_data['name'] = poi_data['name'].replace('SPAR', 'Spar')
92
                    ref_match = PATTERN_SPAR_REF.search(poi_data['name'])
93
                    self.data.ref = ref_match.group(
94
                        1).strip() if ref_match is not None else None
95
                    self.data.city = clean_city(poi_data['city'])
96
                    self.data.postcode = poi_data.get('zipCode').strip()
97
                    self.data.branch = poi_data['name'].split('(')[0].strip()
98
                    self.data.website = poi_data['pageUrl'].strip()
99
                    self.data.lat, self.data.lon = check_hu_boundary(
100
                        poi_data['latitude'], poi_data['longitude'])
101
                    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...
102
                        poi_data['address'])
103
                    self.data.original = poi_data['address']
104
                    self.data.public_holiday_open = False
105
                    self.data.add()
106
        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...
107
            logging.exception('Exception occurred')
108
109
            logging.error(e)
110