def save(self) -> None: """ save or export the results """ save_flag = False for key, val in self.datas.items(): if isinstance(val, object): save_flag = True if not save_flag: return file_name = f'{self.name + ( str(moment.now().format("YYYY-MM-DD HH:mm:ss")) if self.pass_history else "" ) }.json' target_path = init_dir(self.save_path / self.name) avatar_path = init_dir(target_path / "avatars") file_path = target_path / file_name final_data = {} for key, val in self.datas.items(): if isinstance(val, dict): continue val_data = val.report() final_data[key] = val_data if not val_data.get("avatar"): continue with (avatar_path / f"{key}.jpeg").open("wb") as img: img.write(b64decode(val.avatar_b64)) if self.update and file_path.exists(): with file_path.open("r") as file: raw_data = loads(file.read()) raw_data.update(final_data) final_data = raw_data with file_path.open("w") as file: file.write(dumps(final_data, indent=4, ensure_ascii=False)) info(f"[=]Saved: {str(file_path.absolute())}")
def extract_maker_with_sherlock(): """ create extract model from sherlock config.json """ URLCODE = "__URLCODE__" reg = re.compile(f"[{string.punctuation+string.whitespace}]") all_types = set() datas = httpx.get( "https://raw.githubusercontent.com/sherlock-project/sherlock/master/sherlock/resources/data.json", verify=False, ).json() script = pathlib.Path("templates.py") with script.open("w") as file: model_str = """ @staticmethod def {}(): T = yield from upload({}) T.title = T.html.pq('title').text() yield T """ for key, val in datas.items(): conf = f"url='''{val['url'].replace('{}',URLCODE)}'''," key = reg.sub("_", key) if not key[0].isalpha(): key = f"site_{key}" types, msg = val.get("errorType"), val.get("errorMsg") all_types.add(types) if not types: continue if types in {"status_code", "response_url"}: pass elif types == "message": conf += f"error_type='text',error_msg='''{msg}'''," file.write(model_str.format(key, conf).replace(URLCODE, "{}")) info(f"{all_types=}") info(f"file saved: {str(script.absolute())}")
def test_info(self): _ = log.info("Test log info") self.assertEqual(_, None)