Commit 526bc360 authored by Neeme Kahusk's avatar Neeme Kahusk

loeb zip faili

parent c8c79fa3
......@@ -3,14 +3,18 @@
"""Tabeldaja makes csv file from Meta-Share export XML
"""
import os
import os.path
import argparse
import re
import csv
import tempfile
from zipfile import ZipFile
from pathlib import Path
from lxml import etree
import csv
from prepare import read_xml
......@@ -22,6 +26,16 @@ def get_xpath(root: etree._ElementTree, xpath: str):
return ', '.join(texts)
def zip2roots(infile: str) -> list:
olist = []
with tempfile.TemporaryDirectory() as tmpdirname:
with ZipFile(infile) as myzip:
myzip.extractall(tmpdirname)
p = Path(tmpdirname)
for child in p.iterdir():
olist.append(read_xml(str(child)))
return olist
def main():
parser = argparse.ArgumentParser(description='Avab zip faili')
......@@ -33,8 +47,10 @@ def main():
args = parser.parse_args()
if args.zip:
with ZipFile(args.infile, 'r') as myzip:
print(myzip.namelist())
tulem = zip2roots(args.infile)
for i in tulem:
print(etree.tounicode(i, pretty_print=True))
else:
r = read_xml(args.infile)
print(args.xpath)
......
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