fix clean method

This commit is contained in:
gowthaman.b
2023-06-21 17:52:36 +05:30
parent 4df0f6239b
commit d171652b2a

14
main.py
View File

@@ -43,8 +43,11 @@ class JsonToCsv:
def init_db(self): def init_db(self):
self.counter += 1 self.counter += 1
self.ts = time.strftime('%Y%m%d_%H%M%S', time.localtime()) 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") 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.cur = self.con.cursor()
self.make_tables() self.make_tables()
@@ -204,7 +207,7 @@ class JsonToCsv:
child_attribute = f"{key}_{subKey}" child_attribute = f"{key}_{subKey}"
if child_attribute not in attributes: if child_attribute not in attributes:
attributes.append(child_attribute) attributes.append(child_attribute)
elif value_is_list: elif value_is_list:
existing = children.get(key, {}) existing = children.get(key, {})
children[key] = self.extract_child(value, key, f"{top_level}_", existing) 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")) make_archive(args.output, pathlib.Path(f"{top_level}.zip"))
json_csv = JsonToCsv()
if __name__ == '__main__': if __name__ == '__main__':
if args.verbose >= 1: if args.verbose >= 1:
print(f"args = {args}") print(f"args = {args}")
if args.clean: if args.clean:
for d in args.output.glob("*.csv"): for d in args.output.iterdir():
print(f"will delete {d}") print(f"will delete {d}")
os.unlink(d) os.unlink(d)
json_csv = JsonToCsv()
json_csv.parse_json() json_csv.parse_json()