fix clean method
This commit is contained in:
parent
4df0f6239b
commit
d171652b2a
14
main.py
14
main.py
@ -43,8 +43,11 @@ class JsonToCsv:
|
||||
|
||||
def init_db(self):
|
||||
self.counter += 1
|
||||
self.ts = time.strftime('%Y%m%d_%H%M%S', time.localtime())
|
||||
self.con = sqlite3.connect(args.output / f"data-{args.name}-{self.ts}-{self.counter}.db")
|
||||
self.ts = time.strftime('%Y%m%d-%H%M%S', time.localtime())
|
||||
db_name = args.output / f"data-{args.name}-{self.ts}-{self.counter}.db"
|
||||
if args.verbose > 0:
|
||||
print(f"creating DB {db_name}")
|
||||
self.con = sqlite3.connect(db_name)
|
||||
self.cur = self.con.cursor()
|
||||
self.make_tables()
|
||||
|
||||
@ -204,7 +207,7 @@ class JsonToCsv:
|
||||
child_attribute = f"{key}_{subKey}"
|
||||
if child_attribute not in attributes:
|
||||
attributes.append(child_attribute)
|
||||
|
||||
|
||||
elif value_is_list:
|
||||
existing = children.get(key, {})
|
||||
children[key] = self.extract_child(value, key, f"{top_level}_", existing)
|
||||
@ -266,15 +269,14 @@ class JsonToCsv:
|
||||
make_archive(args.output, pathlib.Path(f"{top_level}.zip"))
|
||||
|
||||
|
||||
json_csv = JsonToCsv()
|
||||
|
||||
if __name__ == '__main__':
|
||||
if args.verbose >= 1:
|
||||
print(f"args = {args}")
|
||||
|
||||
if args.clean:
|
||||
for d in args.output.glob("*.csv"):
|
||||
for d in args.output.iterdir():
|
||||
print(f"will delete {d}")
|
||||
os.unlink(d)
|
||||
|
||||
json_csv = JsonToCsv()
|
||||
json_csv.parse_json()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user