hu_oil.constains()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 1
dl 0
loc 11
rs 9.85
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_opening_hours, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
Unused Code introduced by
Unused clean_opening_hours imported from osm_poi_matchmaker.libs.address
Loading history...
10
        clean_phone_to_str
11
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
12
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, 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
22
class hu_oil(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_oil" 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 = 'http://www.oil-benzinkutak.hu/wp-admin/admin-ajax.php?action=store_search&lat=47.162494&lng=19.5033041&max_results=1&search_radius=50&autoload=1'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (166/100).

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

Loading history...
26
        self.tags = {'amenity': 'fuel', 'name': 'OIL!', 'brand': 'OIL!', 'fuel:diesel': 'yes',
27
                     'fuel:octane_95': 'yes', 'brand:wikidata': 'Q2007561',
28
                     'brand:wikipedia': 'OIL! Tankstellen', 'operator': 'Mabanaft Hungary Kft.',
29
                     'operator:addr': '1016 Budapest, Mészáros utca 58/B',
30
                     'ref:vatin:hu': '12700226-2-44', 'ref:vatin': 'HU12700226',
31
                     'ref:HU:company': '01-09-699184',
32
                     'contact:facebook': 'https://www.facebook.com/OILHungary/', }
33
        self.filetype = FileType.json
34
        self.filename = '{}.{}'.format(self.__class__.__name__, self.filetype.name)
35
36
    def types(self):
37
        huoilfu = self.tags.copy()
38
        huoilfu.update(POS_HU_GEN)
39
        huoilfu.update(PAY_CASH)
40
        self.__types = [
41
            {'poi_code': 'huoilfu', 'poi_name': 'OIL!', 'poi_type': 'fuel',
42
             'poi_tags': huoilfu, 'poi_url_base': 'https://www.oil-benzinkutak.hu', 'poi_search_name': '(oil|oil!|oil benzinkutak|oil-benzinkutak)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (148/100).

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

Loading history...
43
             'osm_search_distance_perfect': 2000, 'osm_search_distance_safe': 450,
44
             'osm_search_distance_unsafe': 60},
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
                    try:
56
                        self.data.name = 'OIL!'
57
                        self.data.code = 'huoilfu'
58
                        if poi_data.get('zip') is not None and poi_data.get('zip') != '':
59
                            self.data.postcode = poi_data.get('zip').strip()
60
                        if poi_data.get('city') is not None and poi_data.get('city') != '':
61
                            self.data.city = clean_city(poi_data.get('city'))
62
                        self.data.lat, self.data.lon = check_hu_boundary(
63
                            poi_data.get('lat'), poi_data.get('lng'))
64
                        if poi_data.get('address') is not None and poi_data.get('address') != '':
65
                            self.data.original = poi_data.get('address')
66
                            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...
67
                                extract_street_housenumber_better_2(
68
                                    poi_data.get('address'))
69
                        if poi_data.get('phone') is not None and poi_data.get('phone') != '':
70
                            self.data.phone = clean_phone_to_str(
71
                                poi_data.get('phone'))
72
                        self.data.fuel_octane_95 = True
73
                        self.data.fuel_diesel = True
74
                        if poi_data.get('id') is not None and poi_data.get('id') != '':
75
                            self.data.ref = poi_data.get('id').strip()
76
                        if poi_data.get('url') is not None and poi_data.get('url') != '':
77
                            self.data.website = poi_data.get('url').strip()
78
                        else:
79
                            self.data.website = 'https://www.oil-benzinkutak.hu'
80
                        if poi_data.get('store') is not None and poi_data.get('store') != '':
81
                            tmp = poi_data.get('store').split(' ', 1)
82
                            self.data.branch = tmp[1].strip().capitalize()
83
                        self.data.add()
84
                    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...
85
                        logging.error(e)
86
                        logging.error(poi_data)
87
                        logging.exception('Exception occurred')
88
89
        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...
90
            logging.error(e)
91
            logging.exception('Exception occurred')
92