Test Failed
Push — master ( 8192fe...83ef1f )
by Steffen
02:25
created

saucenao.saucenao   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 274
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 31
eloc 152
dl 0
loc 274
rs 9.8
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A SauceNao.merge_results() 0 17 4
A SauceNao.filter_results() 0 14 3
B SauceNao.__init__() 0 32 1
A SauceNao.merge_two_dicts() 0 11 1
B SauceNao.check_image() 0 56 6
B SauceNao.parse_results_html_to_json() 0 43 6
A SauceNao.check_file() 0 20 2
A SauceNao.parse_results_json() 0 10 3
B SauceNao.get_content_value() 0 15 5
1
#!/usr/bin/python
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
# -*- coding: utf-8 -*-
3
import json
4
import logging
5
import os
6
import os.path
7
import re
8
import time
9
from mimetypes import MimeTypes
10
from typing import Generator
0 ignored issues
show
introduced by
Unable to import 'typing'
Loading history...
Unused Code introduced by
Unused Generator imported from typing
Loading history...
11
12
import requests
13
from bs4 import BeautifulSoup as Soup
14
from bs4 import element
0 ignored issues
show
Unused Code introduced by
Unused element imported from bs4
Loading history...
15
16
from saucenao import http
17
18
try:
19
    from titlesearch import get_similar_titles
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Unused Code introduced by
Unused get_similar_titles imported from titlesearch
Loading history...
20
except ImportError:
21
    get_similar_titles = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
22
23
from saucenao.exceptions import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like saucenao.exceptions should generally be avoided.
Loading history...
Unused Code introduced by
InvalidOrWrongApiKeyException was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DailyLimitReachedException was imported with wildcard, but is not used.
Loading history...
introduced by
Imports from package saucenao are not grouped
Loading history...
24
25
26
class SauceNao(object):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (13/7)
Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
27
    """"
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
28
    small script to work with SauceNao locally
29
    """
30
31
    SEARCH_POST_URL = 'http://saucenao.com/search.php'
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
32
33
    # basic account allows currently 20 images within 30 seconds
34
    # you can increase this value is you have a premium account
35
    LIMIT_30_SECONDS = 20
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
36
37
    # 0=html, 2=json but json is omitting important data but includes more data about authors
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/80).

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

Loading history...
38
    # taken from the API documentation(requires login): https://saucenao.com/user.php?page=search-api
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/80).

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

Loading history...
39
    API_HTML_TYPE = 0
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
40
    API_JSON_TYPE = 2
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
41
42
    CONTENT_CATEGORY_KEY = 'Material'
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
43
    CONTENT_CHARACTERS_KEY = 'Characters'
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
44
45
    mime = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
46
    logger = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
47
48
    def __init__(self, directory, databases=999, minimum_similarity=65, combine_api_types=False, api_key=None,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
best-practice introduced by
Too many arguments (12/5)
Loading history...
49
                 exclude_categories='', move_to_categories=False, output_type=API_HTML_TYPE, start_file=None,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/80).

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

Loading history...
50
                 log_level=logging.ERROR, title_minimum_similarity=90):
51
        """Initializing function
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
52
53
        :type directory: str
54
        :type databases: int
55
        :type minimum_similarity: float
56
        :type combine_api_types: bool
57
        :type api_key: str
58
        :type exclude_categories: str
59
        :type move_to_categories: bool
60
        :type start_file: str
61
        :type log_level: int
62
        :type title_minimum_similarity: float
63
        """
64
        self._directory = directory
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
65
        self._databases = databases
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
66
        self._minimum_similarity = minimum_similarity
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
67
        self._combine_api_types = combine_api_types
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
68
        self._api_key = api_key
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
69
        self._exclude_categories = exclude_categories
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
70
        self._move_to_categories = move_to_categories
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
71
        self._output_type = output_type
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
72
        self._start_file = start_file
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
73
        self._title_minimum_similarity = title_minimum_similarity
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
74
75
        self._previous_status_code = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
76
77
        self.mime = MimeTypes()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
78
        logging.basicConfig(level=log_level)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
79
        self.logger = logging.getLogger("saucenao_logger")
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
80
81
    def check_file(self, file_name: str) -> list:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
82
        """Check the given file for results on SauceNAO
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
83
84
        :type file_name: str
85
        :return:
86
        """
87
        self.logger.info("checking file: {0:s}".format(file_name))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
88
        if self._combine_api_types:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
89
            result = self.check_image(file_name, self.API_HTML_TYPE)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
90
            sorted_results = self.parse_results_json(result)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
91
92
            additional_result = self.check_image(file_name, self.API_JSON_TYPE)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
93
            additional_sorted_results = self.parse_results_json(additional_result)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
94
            sorted_results = self.merge_results(sorted_results, additional_sorted_results)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
95
        else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
96
            result = self.check_image(file_name, self._output_type)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
97
            sorted_results = self.parse_results_json(result)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
98
99
        filtered_results = self.filter_results(sorted_results)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
100
        return filtered_results
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
101
102
    def check_image(self, file_name: str, output_type: int) -> str:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
103
        """Check the possible sources for the given file
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
104
105
        :type output_type: int
106
        :type file_name: str
107
        :return:
108
        """
109
        file_path = os.path.join(self._directory, file_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
110
111
        files = {'file': open(file_path, 'rb').read()}
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
112
        headers = {
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
113
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/80).

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

Loading history...
114
                          'Chrome/63.0.3239.84 Safari/537.36',
115
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/80).

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

Loading history...
116
            'Accept-Language': 'en-DE,en-US;q=0.9,en;q=0.8',
117
            'Accept-Encoding': 'gzip, deflate, br',
118
            'DNT': '1',
119
            'Connection': 'keep-alive'
120
        }
121
        params = {
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
122
            'file': file_path,
123
            'Content-Type': self.mime.guess_type(file_path),
124
            # parameters taken from form on main page: https://saucenao.com/
125
            'url': None,
126
            'frame': 1,
127
            'hide': 0,
128
            # parameters taken from API documentation: https://saucenao.com/user.php?page=search-api
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (100/80).

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

Loading history...
129
            'output_type': output_type,
130
            'db': self._databases,
131
        }
132
133
        if self._api_key:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
134
            params['api_key'] = self._api_key
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
135
136
        link = requests.post(url=self.SEARCH_POST_URL, files=files, params=params, headers=headers)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (99/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
137
138
        code, msg = http.verify_status_code(link, file_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
139
140
        if code == http.STATUS_CODE_SKIP:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
141
            self.logger.error(msg)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
142
            return json.dumps({'results': []})
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
143
        elif code == http.STATUS_CODE_REPEAT:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
144
            if not self._previous_status_code:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
145
                self._previous_status_code = code
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
146
                self.logger.info("Received an unexpected status code, repeating after 10 seconds...")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
147
                time.sleep(10)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
148
                return self.check_image(file_name, output_type)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
149
            else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
150
                raise UnknownStatusCodeException(msg)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Comprehensibility Best Practice introduced by
The variable UnknownStatusCodeException does not seem to be defined.
Loading history...
151
        else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
152
            self._previous_status_code = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
153
154
        if output_type == self.API_HTML_TYPE:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
155
            return self.parse_results_html_to_json(link.text)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
156
157
        return link.text
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
158
159
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
160
    def parse_results_html_to_json(html: str) -> str:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
161
        """Parse the results and sort them descending by similarity
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
162
163
        :type html: str
164
        :return:
165
        """
166
        soup = Soup(html, 'html.parser')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
167
        # basic format of json API response
168
        results = {'header': {}, 'results': []}
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
169
170
        for res in soup.find_all('td', attrs={"class": "resulttablecontent"}):  # type: element.Tag
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (99/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
171
            # optional field in SauceNao
172
            title_tag = res.find_next('div', attrs={"class": "resulttitle"})
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
173
            if title_tag:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
174
                title = title_tag.text
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
175
            else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
176
                title = ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
177
178
            # mandatory field in SauceNao
179
            similarity = res.find_next('div', attrs={"class": "resultsimilarityinfo"}).text.replace('%', '')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
180
            alternate_links = [a_tag['href'] for a_tag in
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
181
                               res.find_next('div', attrs={"class": "resultmiscinfo"}).find_all('a', href=True)]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/80).

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

Loading history...
182
            content_column = []
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
183
            content_column_tags = res.find_all('div', attrs={"class": "resultcontentcolumn"})
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
184
            for content_column_tag in content_column_tags:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
185
                for br in content_column_tag.find_all('br'):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style Naming introduced by
The name br does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
186
                    br.replace_with('\n')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
187
                content_column.append(content_column_tag.text)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
188
189
            result = {
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
190
                'header': {
191
                    'similarity': similarity
192
                },
193
                'data': {
194
                    'title': title,
195
                    'content': content_column,
196
                    'ext_urls': alternate_links
197
                }
198
            }
199
            results['results'].append(result)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
200
201
        return json.dumps(results)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
202
203
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
204
    def parse_results_json(text: str) -> list:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
205
        """Parse the results and sort them descending by similarity
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
206
207
        :type text: str
208
        :return:
209
        """
210
        result = json.loads(text)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
211
        results = [res for res in result['results']]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
212
        return sorted(results, key=lambda k: float(k['header']['similarity']), reverse=True)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
213
214
    def filter_results(self, sorted_results) -> list:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
215
        """Return results with a similarity bigger or the same as the defined similarity from the arguments (default 65%)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
216
217
        :type sorted_results: list|tuple|Generator
218
        :return:
219
        """
220
        filtered_results = []
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
221
        for res in sorted_results:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
222
            if float(res['header']['similarity']) >= float(self._minimum_similarity):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
223
                filtered_results.append(res)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
224
            else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
225
                # we can break here since the results are sorted by similarity anyways
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

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

Loading history...
226
                break
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
227
        return filtered_results
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
228
229
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
230
    def get_content_value(results, key: str):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
231
        """Return the first match of Material in content
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
232
        multiple sites have a categorisation which SauceNao utilizes to provide it in the content section
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/80).

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

Loading history...
233
234
        :type results: list|tuple|Generator
235
        :type key: str
236
        :return:
237
        """
238
        for result in results:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
239
            if 'content' in list(result['data'].keys()):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
240
                for content in result['data']['content']:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
241
                    if re.match('{0:s}: .*'.format(key), content):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
242
                        return ''.join(re.split(r'{0:s}: '.format(key), content)[1:]).rstrip("\n").split('\n')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
243
        return ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
244
245
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
246
    def merge_two_dicts(x: dict, y: dict) -> dict:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style Naming introduced by
The name x does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
Coding Style Naming introduced by
The name y does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
247
        """Take x dictionary and insert/overwrite y dictionary values
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
248
249
        :type x: dict
250
        :type y: dict
251
        :return:
252
        """
253
        z = x.copy()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style Naming introduced by
The name z does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
254
        z.update(y)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
255
        return z
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
256
257
    def merge_results(self, result: list, additional_result: list) -> list:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
258
        """Merge two result arrays
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
259
260
        :type result: list
261
        :type additional_result: list
262
        :return:
263
        """
264
        if len(result) <= len(additional_result):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
265
            length = len(result)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
266
        else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
267
            length = len(additional_result)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
268
269
        for i in range(length):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
270
            for key in list(result[i].keys()):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
271
                result[i][key] = self.merge_two_dicts(result[i][key], additional_result[i][key])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (96/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
272
273
        return result
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
274