import json import sqlite3 import glob def count_db(dbname): count = 0 with open("./combine.json") as f: results = json.loads(f.read()) for i in results: database = i["db_id"] if database not in [dbname, dbname.removeprefix("new_")]: continue count += 1 return count def filter_all_sqlites_has_data(): sql = "SELECT name FROM sqlite_master WHERE type='table'" for i in glob.glob("./database/**/*.sqlite"): con = sqlite3.connect(i) cur = con.cursor() res = cur.execute(sql) has_data = False yield "new_" + i.split("/")[2] # for j in res.fetchall(): # count_sql = "SELECT COUNT(*) FROM {}".format(j[0]) # result = cur.execute(count_sql).fetchone() # if result[0]: # has_data = True # if has_data: # yield "new_" + i.split("/")[2] def count_all(): total_count = 0 for i in filter_all_sqlites_has_data(): total_count += count_db(i) print(total_count) if __name__ == "__main__": count_all()