hu_dm.constains()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 1
dl 0
loc 12
rs 9.8
c 0
b 0
f 0
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_tag_sets import POS_HU_GEN, PAY_CASH
12
    from osm_poi_matchmaker.utils.data_provider import DataProvider
13
    from osm_poi_matchmaker.utils.enums import FileType
14
except ImportError as err:
15
    logging.error('Error %s import module: %s', __name__, err)
16
    logging.exception('Exception occurred')
17
18
    sys.exit(128)
19
20
21
class hu_dm(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_dm" 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...
22
23
    def constains(self):
24
        self.link = 'https://services.dm.de/storedata/stores/bbox/49%2C16%2C45%2C23'
25
        self.tags = {'shop': 'chemist', 'operator': 'dm Kft.', 'brand': 'dm',
26
                     'brand:wikidata': 'Q266572', 'brand:wikipedia': 'en:Dm-drogerie markt',
27
                     'contact:facebook': 'https://www.facebook.com/dm.Magyarorszag',
28
                     'contact:youtube': 'https://www.youtube.com/user/dmMagyarorszag',
29
                     'contact:instagram': 'https://www.instagram.com/dm_magyarorszag',
30
                     'ref:vatin': 'HU11181530', 'ref:vatin:hu': '11181530-2-44', 'ref:HU:company': '13 09 078006',
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...
31
                     'air_conditioning': 'yes'}
32
        self.filetype = FileType.json
33
        self.filename = '{}.{}'.format(
34
            self.__class__.__name__, self.filetype.name)
35
36
    def types(self):
37
        hudmche = self.tags.copy()
38
        hudmche.update(POS_HU_GEN)
39
        hudmche.update(PAY_CASH)
40
        self.__types = [
41
            {'poi_code': 'hudmche', 'poi_name': 'dm', 'poi_type': 'chemist',
42
             'poi_tags': hudmche, 'poi_url_base': 'https://www.dm.hu', 'poi_search_name': 'dm',
43
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200,
44
             'osm_search_distance_unsafe': 15},
45
        ]
46
        return self.__types
47
48
    def process(self):
49
        try:
0 ignored issues
show
unused-code introduced by
Too many nested blocks (8/5)
Loading history...
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['stores']:
55
                    try:
56
                        if poi_data.get('localeCountry').strip().upper() == 'HU':
57
                            self.data.name = 'dm'
58
                            self.data.code = 'hudmche'
59
                            self.data.postcode = poi_data.get('address')[
60
                                'zip'].strip()
61
                            street_tmp = poi_data.get(
62
                                'address')['street'].split(',')[0]
63
                            self.data.city = clean_city(
64
                                poi_data.get('address')['city'])
65
                            self.data.website = 'https://www.dm.hu{}'.format(
66
                                poi_data.get('storeUrlPath'))
67
                            self.data.original = poi_data.get('address')[
68
                                'street']
69
                            self.data.lat, self.data.lon = \
70
                                check_hu_boundary(poi_data.get('location')[
71
                                                  'lat'], poi_data.get('location')['lon'])
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 14 spaces).
Loading history...
72
                            self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
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...
73
                                extract_street_housenumber_better_2(
74
                                    street_tmp.title())
75
                            if poi_data.get('phone') is not None and poi_data.get('phone') != '':
76
                                self.data.phone = clean_phone_to_str(
77
                                    poi_data.get('phone'))
78
                            if poi_data.get('storeNumber') is not None and poi_data.get('storeNumber') != '':
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

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

Loading history...
79
                                self.data.ref = poi_data.get(
80
                                    'storeNumber').strip()
81
                            opening = poi_data.get('openingDays')
82
                            try:
83
                                for i, d in enumerate(opening):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "d" 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...
Unused Code introduced by
The variable i seems to be unused.
Loading history...
84
                                    if d.get('weekDay') is not None and 1 <= d.get('weekDay') <= 7:
85
                                        day = d.get('weekDay')
86
                                        self.data.day_open(
87
                                            day - 1, d.get('timeSlices')[0].get('opening'))
88
                                        self.data.day_close(
89
                                            day - 1, d.get('timeSlices')[0].get('closing'))
90
                            except (IndexError, KeyError):
91
                                logging.warning(
92
                                    'Exception occurred during opening hours processing')
93
                            self.data.public_holiday_open = False
94
                            self.data.add()
95
                    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...
96
                        logging.error(e)
97
                        logging.error(poi_data)
98
                        logging.exception('Exception occurred')
99
100
        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...
101
            logging.error(e)
102
            logging.exception('Exception occurred')
103