osm_poi_matchmaker.libs.xml   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A download_xml() 0 7 3
B save_downloaded_xml() 0 14 7
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 requests
7
    import os
8
    from lxml import etree
0 ignored issues
show
Unused Code introduced by
Unused etree imported from lxml
Loading history...
9
    from osm_poi_matchmaker.utils import config
10
except ImportError as err:
11
    logging.error('Error %s import module: %s', __name__, err)
12
    logging.exception('Exception occurred')
13
14
    sys.exit(128)
15
16
17
def download_xml(link, verify_link=config.get_download_verify_link()):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
    try:
19
        page = requests.get(link, verify=verify_link)
20
    except requests.exceptions.ConnectionError as e:
0 ignored issues
show
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...
Unused Code introduced by
The variable e seems to be unused.
Loading history...
21
        logging.warning('Unable to open connection.')
22
        return None
23
    return page.content if page.status_code == 200 else None
24
25
26
def save_downloaded_xml(link, file, verify=config.get_download_verify_link()):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
27
    if config.get_download_use_cached_data() == True and os.path.isfile(file):
0 ignored issues
show
introduced by
Comparison to True should be just 'expr'
Loading history...
28
        with open(file, 'r', encoding='utf-8') as content_file:
29
            page = content_file.read()
30
    else:
31
        page = download_xml(link, verify)
32
        if page is not None:
33
            if not os.path.exists(config.get_directory_cache_url()):
34
                os.makedirs(config.get_directory_cache_url())
35
            with open(file, mode='w', encoding='utf-8') as code:
36
                code.write(page.decode('utf-8'))
37
        else:
38
            logging.warning('Skipping dataset.')
39
    return page
40