osm_poi_matchmaker.dataproviders.hu_tesco   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 125
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 18

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_tesco.types() 0 34 1
A hu_tesco.constains() 0 19 1
F hu_tesco.process() 0 63 16
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_gpd
12
    from osm_poi_matchmaker.utils.data_provider import DataProvider
13
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_OTP, PAY_CASH
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_tesco(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_tesco" 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://tesco.hu/Ajax?type=fetch-stores-for-area&reduceBy%5Btab%5D=all&bounds%5Bnw%5D%5Blat%5D=49.631214952216425&bounds%5Bnw%5D%5Blng%5D=11.727758183593778&bounds%5Bne%5D%5Blat%5D=49.631214952216425&bounds%5Bne%5D%5Blng%5D=27.004247441406278&bounds%5Bsw%5D%5Blat%5D=38.45256463471463&bounds%5Bsw%5D%5Blng%5D=11.727758183593778&bounds%5Bse%5D%5Blat%5D=38.45256463471463&bounds%5Bse%5D%5Blng%5D=27.004247441406278&currentCoords%5Blat%5D=44.30719090363816&currentCoords%5Blng%5D=19.366002812500028&instanceUUID=b5c4aa5f-9819-47d9-9e5a-d631e931c007'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (567/100).

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

Loading history...
26
        self.tags = {'operator': 'TESCO-GLOBAL Áruházak Zrt.',
27
                     'operator:addr': '2040 Budaörs, Kinizsi út 1-3.',
28
                     'ref:HU:company': '13-10-040628', 'ref:vatin:hu': '10307078-2-44',
29
                     'ref:vatin': 'HU10307078', 'brand': 'Tesco',
30
                     'brand:wikipedia': 'hu:Tesco', 'brand:wikidata': 'Q487494',
31
                     'internet_access': 'wlan', 'internet_access:fee': 'no',
32
                     'internet_access:ssid': 'tesco-internet',
33
                     'contact:facebook': 'https://www.facebook.com/tescoaruhazak',
34
                     'contact:pinterest': 'https://www.pinterest.com/tescohungary/',
35
                     'contact:youtube': 'https://www.youtube.com/user/TescoMagyarorszag',
36
                     'loyalty_card': 'yes', 'payment:gift_card': 'yes', 'payment:wire_transfer': 'yes',
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...
37
                     'air_conditioning': 'yes'}
38
        self.tags.update(POS_OTP)
39
        self.tags.update(PAY_CASH)
40
        self.filetype = FileType.json
41
        self.filename = '{}.{}'.format(
42
            self.__class__.__name__, self.filetype.name)
43
44
    def types(self):
45
        hutescoexp = {'shop': 'convenience'}
46
        hutescoexp.update(self.tags)
47
        hutescoext = {'shop': 'supermarket',
48
                      'wheelchair': 'yes', 'source:wheelchair': 'website'}
49
        hutescoext.update(self.tags)
50
        hutescosup = {'shop': 'supermarket',
51
                      'wheelchair': 'yes', 'source:wheelchair': 'website'}
52
        hutescosup.update(self.tags)
53
        husmrktexp = {'shop': 'convenience', 'alt_name': 'Tesco Expressz'}
54
        husmrktexp.update(self.tags)
55
        husmrktsup = {'shop': 'supermarket', 'wheelchair': 'yes',
56
                      'source:wheelchair': 'website', 'alt_name': 'Tesco'}
57
        husmrktsup.update(self.tags)
58
        self.__types = [
59
            {'poi_code': 'hutescoexp', 'poi_name': 'Tesco Expressz', 'poi_type': 'shop',
60
             'poi_tags': hutescoexp, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco',
61
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200},
62
            {'poi_code': 'hutescoext', 'poi_name': 'Tesco Extra', 'poi_type': 'shop',
63
             'poi_tags': hutescoext, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco',
64
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 1100},
65
            {'poi_code': 'hutescosup', 'poi_name': 'Tesco', 'poi_type': 'shop',
66
             'poi_tags': hutescosup, 'poi_url_base': 'https://tesco.hu', 'poi_search_name': 'tesco',
67
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 1100},
68
            {'poi_code': 'husmrktexp', 'poi_name': 'S-Market', 'poi_type': 'shop',
69
             'poi_tags': husmrktexp, 'poi_url_base': 'https://tesco.hu',
70
             'poi_search_name': '(tesco|smarket|s-market|s market)',
71
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200},
72
            {'poi_code': 'husmrktsup', 'poi_name': 'S-Market', 'poi_type': 'shop',
73
             'poi_tags': husmrktsup, 'poi_url_base': 'https://tesco.hu',
74
             'poi_search_name': '(tesco|smarket|s-market|s market)',
75
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200},
76
        ]
77
        return self.__types
78
79
    def process(self):
80
        try:
0 ignored issues
show
unused-code introduced by
Too many nested blocks (6/5)
Loading history...
81
            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...
82
                                        self.filetype)
83
            if soup is not None:
84
                # parse the html using beautiful soap and store in variable `soup`
85
                # script = soup.find('div', attrs={'data-stores':True})
86
                text = json.loads(str(soup))
87
                for poi_data in text.get('stores'):
88
                    try:
89
                        # Assign: code, postcode, city, name, branch, website, original, street, housenumber,
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...
90
                        # conscriptionnumber, ref, geom
91
                        self.data.branch = poi_data.get('store_name')
92
                        self.data.ref = poi_data.get('goldid')
93
                        self.data.website = 'https://tesco.hu/aruhazak/aruhaz/{}/'.format(
94
                            poi_data.get('urlname'))
95
                        opening = json.loads(poi_data.get('opening'))
96
                        for i in range(0, 7):
97
                            ind = str(i + 1) if i != 6 else '0'
98
                            if ind in opening:
99
                                self.data.day_open(i, opening[ind][0])
100
                                self.data.day_close(i, opening[ind][1])
101
                        self.data.lat, self.data.lon = check_hu_boundary(
102
                            poi_data.get('gpslat'), poi_data.get('gpslng'))
103
                        self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
104
                            extract_street_housenumber_better_2(
105
                                poi_data.get('address'))
106
                        self.data.postcode = poi_data.get('zipcode').strip()
107
                        self.data.city = clean_city(query_osm_city_name_gpd(
108
                            self.session, self.data.lat, self.data.lon))
109
                        if 'xpres' in poi_data.get('name'):
110
                            if self.data.city not in ['Győr', 'Sopron', 'Mosonmagyaróvár', 'Levél']:
111
                                self.data.name = 'Tesco Expressz'
112
                                self.data.code = 'hutescoexp'
113
                            else:
114
                                self.data.name = 'S-Market'
115
                                self.data.code = 'husmrktexp'
116
                        elif 'xtra' in poi_data.get('name'):
117
                            self.data.name = 'Tesco Extra'
118
                            self.data.code = 'hutescoext'
119
                        else:
120
                            if self.data.city not in ['Levél']:
121
                                self.data.name = 'Tesco'
122
                                self.data.code = 'hutescosup'
123
                            else:
124
                                self.data.name = 'S-Market'
125
                                self.data.code = 'husmrktsup'
126
                        self.data.original = poi_data.get('address')
127
                        if poi_data.get('phone') is not None and poi_data.get('phone') != '':
128
                            self.data.phone = clean_phone_to_str(
129
                                poi_data.get('phone'))
130
                        if poi_data.get('goldid') is not None and poi_data.get('goldid') != '':
131
                            self.data.ref = poi_data.get('goldid').strip()
132
                        self.data.public_holiday_open = False
133
                        self.data.add()
134
                    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...
135
                        logging.error(e)
136
                        logging.error(poi_data)
137
                        logging.exception('Exception occurred')
138
139
        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...
140
            logging.error(e)
141
            logging.exception('Exception occurred')
142