Commit d9c6be7d authored by Neeme Kahusk's avatar Neeme Kahusk

puhtamaks ja doc - kõik

parent 784ca908
......@@ -17,7 +17,13 @@ from configure_columns import SIMPLE
XPATHLIST = SIMPLE
def make_filter(tabelifail: str = 'tulbad.csv'):
def make_filter(tabelifail: str = 'tulbad.csv') -> list:
"""Reads "columns file" (columns 'label', 'simplepath', 'xpath' etc. and returns
possible list of labels (possible columns for query).
:param tabelifail: name of columns file
:return: list of columns
"""
with open(tabelifail) as tf:
reader = csv.DictReader(tf, dialect=csv.excel_tab)
csvdata = [x for x in reader]
......@@ -26,15 +32,25 @@ def make_filter(tabelifail: str = 'tulbad.csv'):
return labels_et
def get_xpath(root: etree._ElementTree, xpath: str):
def get_xpath(root: etree._ElementTree, xpath: str) -> :
"""Returns text attribute(s) of XML Elements returned by xpath query.
:param root: etree._ElementTree xml root
:param xpath: xpath as string
:return: string (joined list of xpath results)
"""
namespaces = {'x':'http://www.ilsp.gr/META-XMLSchema'}
elements = root.xpath(xpath, namespaces=namespaces)
texts = [x.text for x in elements]
return ', '.join(texts)
def zip2roots(infile: str) -> list:
"""Reads zipped infile and returns list of xml roots (etree._ElementTree)
:param infile: name of zip file
:return: list of xml roots
"""
olist = []
with tempfile.TemporaryDirectory() as tmpdirname:
with ZipFile(infile) as myzip:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment