Last active
April 22, 2022 21:43
-
-
Save Janderson/8e63ab7d7e361082898cda3f184a92b5 to your computer and use it in GitHub Desktop.
XMind 8 to csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xml.etree.ElementTree as xmlET | |
| import pandas as pd | |
| import click | |
| from zipfile import ZipFile | |
| @click.group() | |
| def cli(): | |
| pass | |
| @cli.command("tocsv") | |
| @click.argument("filename") | |
| def cmd(filename): | |
| read_zip(filename) | |
| def read_zip(filename): | |
| with ZipFile(filename) as myzip: | |
| with myzip.open('content.xml') as xml_file: | |
| read_xml(filename, xml_file.read()) | |
| def read_xml(filename, data): | |
| xml = xmlET.fromstring(data) | |
| items = [] | |
| for it in xml.iter(): | |
| item = { | |
| "text": it.text, | |
| "tag": it.tag | |
| } | |
| items.append(item) | |
| df = pd.DataFrame(items) | |
| df["filename"] = filename | |
| df.to_csv(f"{filename}.csv") | |
| print("done") | |
| if __name__ == "__main__": | |
| cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment