for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import logging
import defusedxml.ElementTree as Xml
from pocketutils.core.dot_dict import NestedDotDict
logger = logging.getLogger("mandos")
class HmdbApi:
def fetch(self, hmdb_id: str) -> NestedDotDict:
raise NotImplementedError()
class QueryingHmdbApi(HmdbApi):
url = f"https://hmdb.ca/metabolites/{hmdb_id}.xml"
url
# e.g. https://hmdb.ca/metabolites/HMDB0001925.xml
def _to_json(self, xml):
response = {}
for child in list(xml):
if len(list(child)) > 0:
response[child.tag] = self._to_json(child)
else:
response[child.tag] = child.text or ""
# one-liner equivalent
# response[child.tag] = parseXmlToJson(child) if len(list(child)) > 0 else child.text or ''
This check looks for lines that are too long. You can specify the maximum line length.
return response
__all__ = ["HmdbApi", "QueryingHmdbApi"]