Passed
Push — main ( a07aa0...748456 )
by Douglas
01:55
created

mandos.model.hmdb_api.HmdbApi.fetch()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import logging
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import defusedxml.ElementTree as Xml
0 ignored issues
show
Unused Code introduced by
Unused defusedxml.ElementTree imported as Xml
Loading history...
introduced by
Unable to import 'defusedxml.ElementTree'
Loading history...
4
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
5
6
7
logger = logging.getLogger("mandos")
8
9
10
class HmdbApi:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
11
    def fetch(self, hmdb_id: str) -> NestedDotDict:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
12
        raise NotImplementedError()
13
14
15
class QueryingHmdbApi(HmdbApi):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
16
    def fetch(self, hmdb_id: str) -> NestedDotDict:
17
        url = f"https://hmdb.ca/metabolites/{hmdb_id}.xml"
0 ignored issues
show
Unused Code introduced by
The variable url seems to be unused.
Loading history...
18
        # e.g. https://hmdb.ca/metabolites/HMDB0001925.xml
19
20
    def _to_json(self, xml):
21
        response = {}
22
        for child in list(xml):
23
            if len(list(child)) > 0:
24
                response[child.tag] = self._to_json(child)
25
            else:
26
                response[child.tag] = child.text or ""
27
            # one-liner equivalent
28
            # response[child.tag] = parseXmlToJson(child) if len(list(child)) > 0 else child.text or ''
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
29
        return response
30
31
32
__all__ = ["HmdbApi", "QueryingHmdbApi"]
33