Skip to content

Commit f6bca62

Browse files
committed
Commit
1 parent 3a57f1f commit f6bca62

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 wathipol
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<img src="https://cdn4.iconfinder.com/data/icons/social-media-and-logos-12/32/Logo_telegram_Airplane_Air_plane_paper_airplane-33-256.png" align="right" width="131" />
2+
3+
# TGSessionsConverter
4+
![PyPI](https://img.shields.io/pypi/v/TGSessionsConverter)
5+
![PyPI - License](https://img.shields.io/pypi/l/TGSessionsConverter)
6+
7+
8+
This module is small util for easy converting Telegram sessions to various formats (Telethon, Pyrogram, Tdata)
9+
<hr/>
10+
11+
12+
## Installation
13+
```
14+
$ pip install TGSessionsConverter
15+
```
16+
17+
## Quickstart
18+
19+
1. in the first step: Converting your format to a TelegramSession instance
20+
21+
```python
22+
from tg_converter import TelegramSession
23+
import io
24+
25+
API_ID = 123
26+
API_HASH = "Your API HASH"
27+
28+
# From SQLite telethon\pyrogram session file
29+
session = TelegramSession.from_sqlite_session_file("my_session_file.session", API_ID, API_HASH)
30+
31+
# From SQLite telethon\pyrogram session file bytes stream (io.BytesIO)
32+
with open("my_example_file.session", "rb") as file:
33+
session_stream = io.BytesIO(file.read())
34+
session = TelegramSession.from_telethon_sqlite_stream(session_stream, API_ID, API_HASH)
35+
```
36+
37+
2. Converting TelegramSession instance to the format whats you need
38+
39+
```python
40+
from tg_converter import TelegramSession
41+
42+
session = TelegramSession(...) # See first step to learn how to create from various formats
43+
44+
# To telethon client
45+
client = session.make_telethon(sync=True) # Use MemorySession as default, see docs
46+
client.connect()
47+
client.send_message("me", "Hello, World!")
48+
client.disconnect()
49+
50+
# To telethon session file (SQLite)
51+
session.make_telethon_session_file("telethon.session")
52+
```
53+
54+
## Docs
55+
56+
### How it works
57+
> 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.
58+
59+
60+
61+
### TelegramSession
62+
63+
...
64+
65+
### Converting to the format whats you need
66+
67+
...
68+
69+
70+
## TODO
71+
72+
- [x] From telethon\pyrogram SQLite session file
73+
- [x] From telethon\pyrogram SQLite session stream
74+
- [x] From tdata
75+
- [x] To telethon client object (Sync\Async)
76+
- [x] To telethon SQLite session file
77+
- [x] To pyrogram client object
78+
- [ ] To pyrogram SQLite session file
79+
- [ ] To tdata
80+
- [x] From telethon client object
81+
- [ ] From pyrogram client object
82+
- [ ] CLI usage
83+
- [ ] Write normal docs

setup.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import setuptools
2+
with open("README.md", "r") as fh:
3+
long_description = fh.read()
4+
5+
requirements = [
6+
"opentele==1.15.1",
7+
"tgcrypto==1.2.3",
8+
"pyrogram",
9+
"aiosqlite==0.17.0"
10+
]
11+
12+
setuptools.setup(
13+
name="TGSessionsConverter",
14+
version="0.0.1",
15+
author="nazar",
16+
author_email="nazar.fedorowych@gmail.com",
17+
description="This module is small util for converting Telegram sessions to various formats (Telethon, Pyrogram, Tdata)",
18+
long_description=long_description,
19+
long_description_content_type="text/markdown",
20+
url="https://github.com/wathipol/TGSessionsCoverter",
21+
packages=setuptools.find_packages(),
22+
install_requires=requirements,
23+
classifiers=[
24+
"Programming Language :: Python :: 3.10",
25+
"License :: OSI Approved :: MIT License",
26+
"Operating System :: OS Independent",
27+
],
28+
python_requires='>=3.7',
29+
)

0 commit comments

Comments
 (0)