Last active
December 3, 2021 02:31
-
-
Save ckhung/61a24c96277e53a275015d513634687d to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python3 | |
# https://github.com/pyexcel/pyexcel-ods/issues/41 | |
# pyexcel-ods issue: use "<text:p>" instead of "<text:line-break/>" for newlines (line breaks) in cells | |
import argparse, re, sys, json | |
from pyexcel_ods3 import save_data | |
from warnings import warn | |
parser = argparse.ArgumentParser( | |
description='read many text files into two columns of an ods file, with filenames as the key column and contents as the value column', | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
parser.add_argument('-o', '--outfn', type=str, default='out.ods', | |
help='output file name') | |
parser.add_argument('-s', '--sheet', type=str, default='main', | |
help='sheet name') | |
parser.add_argument('-x', '--keepext', type=bool, default=False, | |
help='keep extension?') | |
parser.add_argument('textfile', nargs='*', help='input files') | |
args = parser.parse_args() | |
sheet = [] | |
for fn in args.textfile: | |
with open(fn) as F: | |
val = F.read() | |
fn = re.search(r'([^/]+$)', fn).group(1) | |
if not args.keepext: | |
fn = re.sub(r'\.\w+$', '', fn) | |
sheet.append([fn, val]) | |
save_data(args.outfn, { args.sheet: sheet }) | |
#args.keycol | |
#print(json.dumps(sheet, ensure_ascii=False)) |
This file contains 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
spine | |
vitamin C | |
antioxidants |
This file contains 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
temperate | |
fiber | |
summer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment