osm_poi_matchmaker.dataproviders.hu_posta_json   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 99
dl 0
loc 112
rs 10
c 0
b 0
f 0
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_posta_json.types() 0 25 1
A hu_posta_json.__init__() 0 15 1
C hu_posta_json.process() 0 42 10
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
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
11
    from osm_poi_matchmaker.libs.poi_dataset import POIDataset
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
POI_POSTA = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=posta'
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...
21
POI_CSEKK = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=csekkautomata',
0 ignored issues
show
Unused Code introduced by
Disallow trailing comma tuple
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (137/100).

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

Loading history...
22
POI_CSOMAG = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=postamachine',
0 ignored issues
show
Unused Code introduced by
Disallow trailing comma tuple
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (137/100).

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

Loading history...
23
POI_POSTA_PONT = 'https://www.posta.hu/szolgaltatasok/posta-srv-postoffice/rest/postoffice/list?searchField=&searchText=&types=postapoint',
0 ignored issues
show
Unused Code introduced by
Disallow trailing comma tuple
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (139/100).

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

Loading history...
24
25
26
class hu_posta_json(DataProvider):
0 ignored issues
show
Coding Style Naming introduced by
Class name "hu_posta_json" 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...
27
28
    def __init__(self, session, link, download_cache, filename='hu_posta.json'):
0 ignored issues
show
Bug introduced by
The __init__ method of the super-class DataProvider is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
29
        self.session = session
30
        self.link = link
31
        self.tags = {'brand': 'Magyar Posta', 'operator': 'Magyar Posta Zrt.', 'ref:vatin:hu': '10901232-2-44',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

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

Loading history...
32
                     'ref:vatin': 'HU10901232', 'brand:wikipedia': 'hu:Magyar Posta Zrt.', 'brand:wikidata': 'Q145614',
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...
33
                     'contact:email': '[email protected]', 'phone': '+3617678200',
34
                     'contact:facebook': 'https://www.facebook.com/MagyarPosta',
35
                     'contact:youtube': 'https://www.youtube.com/user/magyarpostaofficial',
36
                     'contact:instagram': 'https://www.instagram.com/magyar_posta_zrt/',
37
                     'payment:cash': 'yes', 'payment:debit_cards': 'yes'}
38
        self.filetype = FileType.json
39
        self.filename = '{}.{}'.format(
40
            self.__class__.__name__, self.filetype.name)
41
        self.download_cache = download_cache
42
        self.filename = filename
43
44
    def types(self):
45
        hupostapo = {'amenity': 'post_office'}
46
        hupostapo.update(self.tags)
47
        hupostacse = {'amenity': 'vending_machine', 'vending': 'cheques'}
48
        hupostacse.update(self.tags)
49
        hupostacso = {'amenity': 'vending_machine', 'vending': 'parcel_pickup'}
50
        hupostacso.update(self.tags)
51
        hupostapp = {'amenity': 'post_office'}
52
        hupostapp.update(self.tags)
53
        hupostamp = {'amenity': 'post_office'}
54
        hupostamp.update(self.tags)
55
56
        data = [
57
            {'poi_code': 'hupostapo', 'poi_name': 'Posta', 'poi_type': 'post_office',
58
             'poi_tags': hupostapo, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'},
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
59
            {'poi_code': 'hupostacse', 'poi_name': 'Posta csekkautomata', 'poi_type': 'vending_machine_cheques',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

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

Loading history...
60
             'poi_tags': hupostacse, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'},
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...
61
            {'poi_code': 'hupostacso', 'poi_name': 'Posta csomagautomata',
62
             'poi_type': 'vending_machine_parcel_pickup',
63
             'poi_tags': hupostacso, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': '(mpl|posta)'},
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

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

Loading history...
64
            {'poi_code': 'hupostapp', 'poi_name': 'PostaPont', 'poi_type': 'post_office',
65
             'poi_tags': hupostapp, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': '(postapont|posta)'},
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...
66
            {'poi_code': 'hupostamp', 'poi_name': 'Mobilposta', 'poi_type': 'post_office',
67
             'poi_tags': hupostamp, 'poi_url_base': 'https://www.posta.hu', 'poi_search_name': 'posta'}]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
68
        return data
69
70
    def process(self):
71
        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 (109/100).

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

Loading history...
72
                                    self.filetype)
73
        if soup is not None:
74
            text = json.loads(soup)
75
            data = POIDataset()
76
            for poi_data in text['items']:
77
                if poi_data['type'] == 'posta':
78
                    if 'mobilposta' in poi_data['name']:
79
                        data.name = 'Mobilposta'
80
                        data.code = 'hupostamp'
81
                    else:
82
                        data.name = 'Posta'
83
                        data.code = 'hupostapo'
84
                        data.public_holiday_open = False
85
                elif poi_data['type'] == 'csekkautomata':
86
                    data.name = 'Posta csekkautomata'
87
                    data.code = 'hupostacse'
88
                    data.public_holiday_open = True
89
                elif poi_data['type'] == 'postamachine':
90
                    data.name = 'Posta csomagautomata'
91
                    data.code = 'hupostacso'
92
                    data.public_holiday_open = True
93
                elif poi_data['type'] == 'postapoint':
94
                    data.name = 'PostaPont'
95
                    data.code = 'hupostapp'
96
                    data.public_holiday_open = False
97
                else:
98
                    logging.error('Non existing Posta type.')
99
                data.postcode = poi_data['zipCode'].strip()
100
                data.city = clean_city(poi_data['city'])
101
                data.branch = poi_data['name']
102
                data.lat = poi_data['lat']
103
                data.lon = poi_data['lng']
104
                data.street, data.housenumber, 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 (109/100).

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

Loading history...
105
                    poi_data['address'])
106
                data.original = poi_data['address']
107
                data.add()
108
            if data is None or data.lenght() < 1:
109
                logging.warning('Resultset is empty. Skipping ...')
110
            else:
111
                insert_poi_dataframe(self.session, data.process())
112