Code Monkey home page Code Monkey logo

tgconvertor's Introduction

Hi there, I'm Nazar

Python developer from Ukraine πŸ‡ΊπŸ‡¦

tgconvertor's People

Contributors

nazar220160 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tgconvertor's Issues

import error

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'

No account has been loaded

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?

unexpected argument 'date'

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'

telethon to pyrogram session dont work

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())

Pyrogram to tdata dont work

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'

Problem after Converting TELETHON Sessions to PyroGram

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"

Define the main function

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")

Call the function in the main function

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")

Check if the script is being run as the main program

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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.