osm_poi_matchmaker.dataproviders.hu_foxpost   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 16.25 %

Importance

Changes 0
Metric Value
eloc 69
dl 13
loc 80
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_foxpost.types() 0 10 1
B hu_foxpost.process() 0 32 6
A hu_foxpost.constains() 13 13 1

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.libs.soup import save_downloaded_soup
9
    from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city, clean_opening_hours
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/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.utils.enums import WeekDaysLongHUUnAccented
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_foxpost(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_foxpost" 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 View Code Duplication
    def constains(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
24
        self.link = 'https://cdn.foxpost.hu/foxpost_terminals_extended_v3.json'
25
        self.tags = {'brand': 'Foxpost', 'operator': 'FoxPost Zrt.',
26
                     'operator:addr': '3200 Gyöngyös, Batsányi János utca 9.', 'ref:vatin': 'HU25034644',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
27
                     'ref:vatin:hu': '25034644-2-10', 'ref:HU:company': '10 10 020309',
28
                     'contact:facebook': 'https://www.facebook.com/foxpostzrt',
29
                     'contact:youtube': 'https://www.youtube.com/channel/UC3zt91sNKPimgA32Nmcu97w',
30
                     'contact:email': '[email protected]', 'phone': '+36 1 999 03 69',
31
                     'payment:contactless': 'yes', 'payment:mastercard': 'yes', 'payment:visa': 'yes',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
32
                     'payment:cash': 'no', }
33
        self.filetype = FileType.json
34
        self.filename = '{}.{}'.format(
35
            self.__class__.__name__, self.filetype.name)
36
37
    def types(self):
38
        hufoxpocso = {'amenity': 'vending_machine',
39
                      'vending': 'parcel_pickup;parcel_mail_in'}
40
        hufoxpocso.update(self.tags)
41
        self.__types = [
42
            {'poi_code': 'hufoxpocso', 'poi_name': 'Foxpost', 'poi_type': 'vending_machine_parcel_pickup_and_mail_in',
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...
43
             'poi_tags': hufoxpocso, 'poi_url_base': 'https://www.foxpost.hu', 'poi_search_name': 'foxpost',
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...
44
             'osm_search_distance_perfect': 1000, 'osm_search_distance_safe': 400, 'osm_search_distance_unsafe': 20},
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...
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:
55
                    self.data.name = 'Foxpost'
56
                    self.data.code = 'hufoxpocso'
57
                    self.data.postcode = poi_data['zip'].strip()
58
                    self.data.city = clean_city(poi_data['city'])
59
                    self.data.branch = poi_data['name']
60
                    for i in range(0, 7):
61
                        if poi_data['open'][WeekDaysLongHUUnAccented(i).name.lower()] is not None:
62
                            opening, closing = clean_opening_hours(
63
                                poi_data['open'][WeekDaysLongHUUnAccented(i).name.lower()])
64
                            self.data.day_open(i, opening)
65
                            self.data.day_close(i, closing)
66
                        else:
67
                            self.data.day_open_close(i, None, None)
68
                    self.data.original = poi_data['address']
69
                    self.data.lat, self.data.lon = check_hu_boundary(
70
                        poi_data['geolat'], poi_data['geolng'])
71
                    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...
72
                        poi_data['street'])
73
                    self.data.public_holiday_open = False
74
                    self.data.description = poi_data.get('findme')
75
                    self.data.add()
76
        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...
77
            logging.exception('Exception occurred')
78
79
            logging.error(e)
80