add a zip thingy
This commit is contained in:
parent
5741838fca
commit
b737c35119
12
main.py
12
main.py
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import pathlib
|
||||
import time
|
||||
import shutil
|
||||
|
||||
import ijson
|
||||
import sqlite3
|
||||
@ -13,6 +14,7 @@ parser.add_argument("--output", help="folder to place csv", required=True, type=
|
||||
parser.add_argument("--delimiter", help="delimiter for CSV (default is '|'", default="|")
|
||||
parser.add_argument("--single", action="store_true", help="merge all json files to single output csv")
|
||||
parser.add_argument("--debug", action="store_true", help="print debug logs")
|
||||
parser.add_argument("--zip", action="store_true", help="make a zipfile of all outputs")
|
||||
parser.add_argument("--metadata", type=int, help="how many records to parse for building metadata", default=1000)
|
||||
parser.add_argument("--join-column", help="join column from top-level to merge nested json", required=True)
|
||||
parser.add_argument("--name", help="base name, to be used in creating all data", required=True)
|
||||
@ -20,6 +22,13 @@ parser.add_argument("--name", help="base name, to be used in creating all data",
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def make_archive(source: pathlib.Path, destination: pathlib.Path) -> None:
|
||||
base_name = destination.parent / destination.stem
|
||||
fmt = destination.suffix.replace(".", "")
|
||||
root_dir = source.parent
|
||||
base_dir = source.name
|
||||
shutil.make_archive(str(base_name), fmt, root_dir, base_dir)
|
||||
|
||||
class DBConn:
|
||||
def __init__(self):
|
||||
self.cur = None
|
||||
@ -232,6 +241,9 @@ class DBConn:
|
||||
self.con.commit()
|
||||
self.make_csv_from_tables()
|
||||
|
||||
if args.zip:
|
||||
make_archive(args.output, pathlib.Path(f"{top_level}.zip"))
|
||||
|
||||
|
||||
dbConn = DBConn()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user