nazar220160 / tgconvertor Goto Github PK
View Code? Open in Web Editor NEWThis module is small util for easy converting Telegram sessions to various formats
License: MIT License
This module is small util for easy converting Telegram sessions to various formats
License: MIT License
from TGConvertor.manager.manager import SessionManager
Traceback (most recent call last):
File "D:\MyProjects\project\app.py", line 7, in
from BotCore.handlers.main_router import router
File "D:\MyProjects\project\BotCore\handlers_init_.py", line 1, in
from . import (
File "D:\MyProjects\project\BotCore\handlers\accoutns_init_.py", line 1, in
from . import (
File "D:\MyProjects\project\BotCore\handlers\accoutns\AccountsAddForm.py", line 5, in
from TGConvertor.manager.manager import SessionManager
File "D:\MyProjects\project\venv\lib\site-packages\TGConvertor_init_.py", line 8, in
from .manager import manager
File "D:\MyProjects\project\venv\lib\site-packages\TGConvertor\manager\manager.py", line 6, in
from .sessions.pyro import PyroSession
File "D:\MyProjects\project\venv\lib\site-packages\TGConvertor\manager\sessions\pyro.py", line 53, in
class PyroSession:
File "D:\MyProjects\project\venv\lib\site-packages\TGConvertor\manager\sessions\pyro.py", line 70, in PyroSession
user_id: None | int = None,
TypeError: unsupported operand type(s) for |: 'NoneType' and 'type'
If I go to telegram using this tdata then everything works, but when I try to load_from_tdata in telethon_client() I get an error.
Again, I repeat that the tdata is valid
I so suspect the problem is with the library, right?
Help me pls. I need function for import telethon.session file and then save this file to TData folder
i connected to pyrogram from tdata file and now i cannot use InputPeerUser to add by id
How to batch convert Telethon session files to Pyrogram session files?
Code:
async def main():
session_name = "998331062104.session"
try:
session = await SessionManager.from_telethon_file(file=f'sessions/tele_sessions/{session_name}')
print(1)
await session.to_pyrogram_file(f'sessions/pyro_sessions/{session_name}')
print(2)
session = await SessionManager.from_pyrogram_file(file=f'sessions/pyro_sessions/{session_name}')
print(3)
except Exception as er:
print(f'Error: {er}')
if __name__ == '__main__':
asyncio.run(main())
Error:
1
2
Error: PyroSession.__init__() got an unexpected keyword argument 'date'
hi
I tried like this, the session is created but is not recognized by pyrogram :(
from TGConvertor.manager.manager import SessionManager
API_ID = ''
API_HASH = ''
async def main():
session_manager = SessionManager(API_ID, API_HASH)
await session_manager.from_telethon_file("1.session")
await session_manager.to_pyrogram_file("01.session")
if name == "main":
import asyncio
asyncio.run(main())
Code :
from TGConvertor import SessionManager
import asyncio
async def main():
session_name = "Gkfjnwejkf.session"
session = await SessionManager.from_pyrogram_file(file=f'{session_name}')
await session.to_tdata_folder(f'{session_name}')
if __name__ == '__main__':
asyncio.run(main())
Error:
Traceback (most recent call last):
File "C:\Python Projects\TGConverter\converter.py", line 11, in <module>
asyncio.run(main())
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Python Projects\TGConverter\converter.py", line 6, in main
session = await SessionManager.from_pyrogram_file(file=f'{session_name}')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python Projects\TGConverter\venv\Lib\site-packages\TGConvertor\manager.py", line 111, in from_pyrogram_file
session = await PyroSession.from_file(file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python Projects\TGConverter\venv\Lib\site-packages\TGConvertor\sessions\pyro.py", line 124, in from_file
return cls(**session)
^^^^^^^^^^^^^^
TypeError: PyroSession.__init__() got an unexpected keyword argument 'date'
session = SessionManager.from_tdata_folder(Path("tdata"))
res = await session.to_pyrogram_file('test.session')
print(res)
--> None
after i converting the sessions, i get an error which says that the pyrogram sessions are 'NoneType' object is not subscriptable
from TGConvertor.manager.manager import SessionManager
from pathlib import Path
import asyncio
API_ID = 4
API_HASH = "014b35b6184100b085b0d0572f9b5103"
async def main():
# Define the path to the Telethon session files folder and the Pyrogram session files folder
telethon_folder = Path("telethon sessions")
pyrogram_folder = Path("pyrogram sessions")
# Iterate over all the files in the Telethon folder
for telethon_session_file in telethon_folder.iterdir():
# check if the file is a session file
if telethon_session_file.suffix == ".session":
print(f'Converting {telethon_session_file.name}')
# Create a session object from the Telethon session file
session = await SessionManager.from_telethon_file(telethon_session_file)
# Define the path for the Pyrogram session file
pyrogram_session_file = pyrogram_folder / telethon_session_file.name
# Convert the session object to a Pyrogram session file
res = await session.to_pyrogram_file(pyrogram_session_file)
print(f'{telethon_session_file.name} converted successfully')
else:
# print a message if the file is not a session file
print(f"{telethon_session_file} is not a session file")
async def write_file_names_to_txt(telethon_folder: Path):
# Define the path for the txt file
txt_file = Path("telethon_session_files.txt")
# Open the txt file in write mode
with open(txt_file, 'w') as f:
# Iterate over all the files in the Telethon folder
for telethon_session_file in telethon_folder.iterdir():
# check if the file is a session file
if telethon_session_file.suffix == ".session":
# Write the file name to the txt file
file_name = telethon_session_file.stem
f.write("{\n")
f.write('"phone":"'+file_name+'",\n'),
f.write('"api_id": 4,\n'),
f.write('"api_hash": "014b35b6184100b085b0d0572f9b5103"')
f.write("},\n")
async def main():
telethon_folder = Path("telethon sessions")
pyrogram_folder = Path("pyrogram sessions")
# call the function here
await write_file_names_to_txt(telethon_folder)
for telethon_session_file in telethon_folder.iterdir():
if telethon_session_file.suffix == ".session":
print(f'Converting {telethon_session_file.name}')
session = await SessionManager.from_telethon_file(telethon_session_file)
pyrogram_session_file = pyrogram_folder / telethon_session_file.name
session = await session.to_pyrogram_file(pyrogram_session_file)
if session is not None:
print(f'{telethon_session_file.name} converted successfully')
# use session object here
else:
print("Error: session object is None")
else:
print(f"{telethon_session_file} is not a session file")
if name == "main":
print("Start converting files")
# Run the main function using the asyncio.run() method
asyncio.run(main())
print("All files have been converted successfully")
Hi @nazar220160 is it possible to convert logged in web telegram auth keys (local storage) to telethon session file and use it in teleton?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.