rename json and session file to phone number
This commit is contained in:
@ -19,11 +19,23 @@ class JsonConverter(BaseSession):
|
||||
banned_dir: Path,
|
||||
proxy: str,
|
||||
json_write: bool = True,
|
||||
rename: bool = False,
|
||||
):
|
||||
"""
|
||||
Конвертер сессий в json
|
||||
base_dir: директория с сессиями
|
||||
errors_dir: директория куда перемещать сессии с ошибками
|
||||
banned_dir: директория куда перемещать забаненные сессии
|
||||
proxy: прокси для подключения формат: http:ip:port:user:pswd
|
||||
json_write: записывать в json файл информацию о string_session + proxy?
|
||||
rename: переименование сессий в формат phone.json и phone.session,
|
||||
где ключ phone - берет из json файла, а также записывает в json файл
|
||||
номер телефона в строку ключ session_file
|
||||
"""
|
||||
super().__init__(base_dir, errors_dir, banned_dir)
|
||||
self.__api_id, self.__api_hash = 2040, "b18441a1ff607e10a989891a5462e627"
|
||||
self.__json_write, self.__rename = json_write, rename
|
||||
self.__proxy = ProxyParser(proxy).asdict_thon
|
||||
self.__json_write = json_write
|
||||
|
||||
def _main(self, item: Path, json_file: Path, json_data: dict) -> dict:
|
||||
"""
|
||||
@ -42,11 +54,20 @@ class JsonConverter(BaseSession):
|
||||
string_session = ss.save()
|
||||
with contextlib.suppress(Exception):
|
||||
asyncio.run(client.disconnect()) # type: ignore
|
||||
del client
|
||||
del ss
|
||||
del client, ss
|
||||
loop.close()
|
||||
json_data["proxy"] = self.__proxy
|
||||
json_data["string_session"] = string_session
|
||||
if self.__rename:
|
||||
if phone := json_data.get("phone"):
|
||||
for char in ["+", " ", "-", "(", ")"]:
|
||||
phone = phone.replace(char, "")
|
||||
if phone.isdigit():
|
||||
json_file.rename(self.base_dir / f"{phone}.json")
|
||||
item.rename(self.base_dir / f"{phone}.session")
|
||||
json_data["session_file"] = phone
|
||||
if not self.__json_write:
|
||||
json_write_sync(json_file, json_data)
|
||||
if self.__json_write:
|
||||
json_write_sync(json_file, json_data)
|
||||
return json_data
|
||||
|
||||
Reference in New Issue
Block a user