import os,sys,re,json # import mysql class Db(): '''Db接口''' def __init__(self): pass def save(domain:str, res:bool): pass class File(Db): '''文件保存结果''' def save(self, filePath: str, res: str): # super().save(res) # 确保目录存在 dir_path = os.path.dirname(filePath) if dir_path and not os.path.exists(dir_path): os.makedirs(dir_path, exist_ok=True) # 使用追加模式写入,如果文件不存在会自动创建 with open(filePath, 'a+', encoding='utf-8') as file: file.write(res + "\n") file.flush() # 确保立即写入磁盘 class Mysql(Db): '''mysql数据库保存数据库''' def save(domain: str, res: bool): return super().save(res) class Sqlite(Db): '''sqlite保存''' def save(domain: str, res: bool): return super().save(res)