Code Monkey home page Code Monkey logo

tgsessionsconverter's Introduction

TGSessionsConverter

PyPI PyPI - License

This module is small util for easy converting Telegram sessions to various formats (Telethon, Pyrogram, Tdata)


Installation

$ pip install TGSessionsConverter

Quickstart

  1. in the first step: Converting your format to a TelegramSession instance
from tg_converter import TelegramSession
import io

API_ID = 123
API_HASH = "Your API HASH"

# From SQLite telethon\pyrogram session file
session = TelegramSession.from_sqlite_session_file("my_session_file.session", API_ID, API_HASH)

# From SQLite telethon\pyrogram session file bytes stream (io.BytesIO)
with open("my_example_file.session", "rb") as file:
    session_stream = io.BytesIO(file.read())
session = TelegramSession.from_telethon_sqlite_stream(session_stream, API_ID, API_HASH)
  1. Converting TelegramSession instance to the format whats you need
from tg_converter import TelegramSession

session = TelegramSession(...) # See first step to learn how to create from various formats

# To telethon client
client = session.make_telethon(sync=True) # Use MemorySession as default, see docs
client.connect()
client.send_message("me", "Hello, World!")
client.disconnect()

# To telethon session file (SQLite)
session.make_telethon_session_file("telethon.session")

Docs

How it works

An authorization session consists of an authorization key and some additional data required to connect. The module simply extracts this data and creates an instance of TelegramSession based on it, the methods of which are convenient to use to convert to the format you need.

TelegramSession

...

Converting to the format whats you need

...

TODO

  • From telethon\pyrogram SQLite session file
  • From telethon\pyrogram SQLite session stream
  • From tdata
  • To telethon client object (Sync\Async)
  • To telethon SQLite session file
  • To pyrogram client object
  • To pyrogram SQLite session file
  • To tdata
  • From telethon client object
  • From pyrogram client object
  • CLI usage
  • Write normal docs

tgsessionsconverter's People

Contributors

gjaylg avatar m4xx1m avatar wathipol 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

Watchers

 avatar  avatar  avatar  avatar

tgsessionsconverter's Issues

Doesnt convert telethon session to pyrogram

Hello, I use this code to convert the session:

async def main():
    session = TelegramSession.from_sqlite_session_file("telethon.session", API_ID, API_HASH)
    await session.make_pyrogram("pyrogram")
asyncio.run(main())

when I run it writes:

Please enter your phone (or bot token):

what to do?)

opentele.exception.OpenTeleException: Unexpected Exception: No account has been loaded [ Called by BaseObject.TDesktop.__loadFromTData() ]

Hello. I don’t understand how to convert tdata into a pyrogram session. I am writing this code:

session = TelegramSession.from_tdata('tdata 2', api_id=api_id,api_hash=api_hash,device_model='MacBook Pro M1 Pro', system_version='macOS 14.2.1', app_version='Telegram macOS 10.8 (259860) APP_STORE')

What I get is this error:
session = TelegramSession.from_tdata('tdata 2', api_id=api_id,api_hash=api_hash,device_model='MacBook Pro M1 Pro', system_version='macOS 14.2.1', app_version='Telegram macOS 10.8 (259860) APP_STORE')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tg_converter/main.py", line 143, in from_tdata
tdesk = TDesktop(path_to_folder)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/td/tdesktop.py", line 141, in init
self.LoadTData()
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/td/tdesktop.py", line 216, in LoadTData
raise e
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/td/tdesktop.py", line 203, in LoadTData
self.__loadFromTData()
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/td/tdesktop.py", line 453, in __loadFromTData
Expects(len(self.accounts) > 0, "No account has been loaded")
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/exception.py", line 326, in Expects
raise exception
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentele/td/tdesktop.py", line 453, in __loadFromTData
Expects(len(self.accounts) > 0, "No account has been loaded")
opentele.exception.OpenTeleException: Unexpected Exception: No account has been loaded [ Called by BaseObject.TDesktop.__loadFromTData() ]

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

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.