Passed
Push — master ( de54f1...6a01a0 )
by KAMI
07:10
created

osm_poi_matchmaker.dataproviders.hu_benu   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 11.11 %

Importance

Changes 0
Metric Value
eloc 77
dl 10
loc 90
rs 10
c 0
b 0
f 0
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_benu.constains() 10 11 1
A hu_benu.types() 0 11 1
C hu_benu.process() 0 41 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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.dao.data_handlers import insert_poi_dataframe
0 ignored issues
show
Unused Code introduced by
Unused insert_poi_dataframe imported from osm_poi_matchmaker.dao.data_handlers
Loading history...
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, 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...
11
        PATTERN_FULL_URL
12
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
13
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH
14
    from osm_poi_matchmaker.utils.data_provider import DataProvider
15
    from osm_poi_matchmaker.utils.enums import FileType
16
except ImportError as err:
17
    logging.error('Error %s import module: %s', __name__, err)
18
    logging.exception('Exception occurred')
19
20
    sys.exit(128)
21
22
23
class hu_benu(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_benu" 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...
24
25 View Code Duplication
    def constains(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
26
        self.link = 'https://benu.hu/wordpress-core/wp-admin/admin-ajax.php?action=asl_load_stores&nonce=1900018ba1&load_all=1&layout=1'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (136/100).

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

Loading history...
27
        self.tags = {'brand': 'Benu gyógyszertár', 'dispensing': 'yes',
28
                     'contact:facebook': 'https://www.facebook.com/BENUgyogyszertar',
29
                     'contact:youtube': 'https://www.youtube.com/channel/UCBLjL10QMtRHdkak0h9exqg',
30
                     'air_conditioning': 'yes', }
31
        self.tags.update(POS_HU_GEN)
32
        self.tags.update(PAY_CASH)
33
        self.filetype = FileType.json
34
        self.filename = '{}.{}'.format(
35
            self.__class__.__name__, self.filetype.name)
36
37
    def types(self):
38
        hubenupha = {'amenity': 'pharmacy'}
39
        hubenupha.update(self.tags)
40
        self.__types = [
41
            {'poi_code': 'hubenupha', 'poi_name': 'Benu gyógyszertár', 'poi_type': 'pharmacy',
42
             'poi_tags': hubenupha, 'poi_url_base': 'https://benu.hu',
43
             'poi_search_name': '(benu gyogyszertár|benu)',
44
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 200,
45
             'osm_search_distance_unsafe': 20, 'preserve_original_name': True},
46
        ]
47
        return self.__types
48
49
    def process(self):
50
        try:
51
            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...
52
                                        self.filetype)
53
            if soup is not None:
54
                text = json.loads(str(soup))
55
                for poi_data in text:
56
                    try:
57
                        if 'BENU Gyógyszertár' not in poi_data.get('title'):
58
                            self.data.name = poi_data.get('title').strip()
59
                            self.data.branch = None
60
                        else:
61
                            self.data.name = 'Benu gyógyszertár'
62
                            self.data.branch = poi_data.get('title').strip()
63
                        self.data.code = 'hubenupha'
64
                        if poi_data.get('description') is not None:
65
                            pu_match = PATTERN_FULL_URL.match(poi_data.get('description'))
66
                            self.data.website = pu_match.group(0).strip() if pu_match is not None else None
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

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

Loading history...
67
                        else:
68
                            self.data.website = None
69
                        self.data.city = clean_city(poi_data.get('city'))
70
                        self.data.postcode = poi_data.get('postal_code').strip()
71
                        self.data.lat, self.data.lon = check_hu_boundary(poi_data.get('lat'), poi_data.get('lng'))
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...
72
                        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 (132/100).

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

Loading history...
73
                            poi_data.get(('street')))
74
                        self.data.original = poi_data.get('street')
75
                        if 'phone' in poi_data and poi_data.get('phone') != '':
76
                            self.data.phone = clean_phone_to_str(
77
                                poi_data.get('phone'))
78
                        else:
79
                            self.data.phone = None
80
                        self.data.public_holiday_open = False
81
                        self.data.add()
82
                    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...
83
                        logging.error(e)
84
                        logging.error(poi_data)
85
                        logging.exception('Exception occurred')
86
87
        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...
88
            logging.error(e)
89
            logging.exception('Exception occurred')
90