tgdata 0.0.3__tar.gz → 0.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tgdata-0.0.3 → tgdata-0.0.5}/PKG-INFO +20 -2
- {tgdata-0.0.3 → tgdata-0.0.5}/README.md +19 -1
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/__init__.py +8 -2
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/connection_engine.py +32 -10
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/message_engine.py +29 -1
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata.egg-info/PKG-INFO +20 -2
- {tgdata-0.0.3 → tgdata-0.0.5}/setup.cfg +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/setup.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/models.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/progress.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/__init__.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/my_test.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_00_connection.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_01_list_group_chats.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_02_get_message_count.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_03_get_all_messages.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_04_get_all_messages_in_batches.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_05_with_progress_feature.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_06_polling_simple.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_07_on_new_message_simple.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_07_real_time_event_handler.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_08_batch_callback.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_08_polling.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_10_advanced_features.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_debug_min_id.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_polling_debug.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/smoke_tests/test_username_support.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/tgdata.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata/utils.py +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata.egg-info/SOURCES.txt +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata.egg-info/dependency_links.txt +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata.egg-info/requires.txt +0 -0
- {tgdata-0.0.3 → tgdata-0.0.5}/tgdata.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgdata
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: A production-grade Python library for extracting and processing Telegram group and channel messages
|
|
5
5
|
Author: enes kuzucu
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -67,10 +67,21 @@ tgdata supports 1 authentication at the moment.
|
|
|
67
67
|
api_id = 1234566
|
|
68
68
|
api_hash = a24adjfakjdfakjshdflkajsbdflk
|
|
69
69
|
phone = +905064004949 # use full phone number including + and country code
|
|
70
|
-
username = 'powerpuffdude'
|
|
71
70
|
|
|
71
|
+
# Where the Telethon session lives (".session" is appended automatically).
|
|
72
|
+
# Use an ABSOLUTE path — a bare name creates the file in whatever directory
|
|
73
|
+
# the process happens to run from. Do not quote values: INI values are raw
|
|
74
|
+
# text, so quotes become part of the value (tgdata strips them defensively
|
|
75
|
+
# since 0.0.4, but don't rely on it).
|
|
76
|
+
session_file = /absolute/path/to/my_session
|
|
72
77
|
```
|
|
73
78
|
|
|
79
|
+
**Session naming precedence** (since 0.0.4): an explicit `session_file`
|
|
80
|
+
always wins. A legacy `username` key is used as the session name only when
|
|
81
|
+
no `session_file` is set — configs that relied on username-named sessions
|
|
82
|
+
keep working, but new configs should set `session_file` and omit `username`
|
|
83
|
+
(it plays no part in authentication).
|
|
84
|
+
|
|
74
85
|
|
|
75
86
|
## Quick Start
|
|
76
87
|
|
|
@@ -181,6 +192,13 @@ messages = await tg.get_messages(
|
|
|
181
192
|
)
|
|
182
193
|
```
|
|
183
194
|
|
|
195
|
+
A numeric id resolves only if the session can actually see the group. On a
|
|
196
|
+
cache miss tgdata syncs the account's chat list once and retries — so fresh
|
|
197
|
+
sessions work for groups the account belongs to. If the group still can't be
|
|
198
|
+
found it raises `tgdata.GroupAccessError` (the account is not a member, or
|
|
199
|
+
the id is wrong) instead of Telethon's generic "Could not find the input
|
|
200
|
+
entity" ValueError.
|
|
201
|
+
|
|
184
202
|
### get_messages with start_date parameter
|
|
185
203
|
|
|
186
204
|
```python
|
|
@@ -41,10 +41,21 @@ tgdata supports 1 authentication at the moment.
|
|
|
41
41
|
api_id = 1234566
|
|
42
42
|
api_hash = a24adjfakjdfakjshdflkajsbdflk
|
|
43
43
|
phone = +905064004949 # use full phone number including + and country code
|
|
44
|
-
username = 'powerpuffdude'
|
|
45
44
|
|
|
45
|
+
# Where the Telethon session lives (".session" is appended automatically).
|
|
46
|
+
# Use an ABSOLUTE path — a bare name creates the file in whatever directory
|
|
47
|
+
# the process happens to run from. Do not quote values: INI values are raw
|
|
48
|
+
# text, so quotes become part of the value (tgdata strips them defensively
|
|
49
|
+
# since 0.0.4, but don't rely on it).
|
|
50
|
+
session_file = /absolute/path/to/my_session
|
|
46
51
|
```
|
|
47
52
|
|
|
53
|
+
**Session naming precedence** (since 0.0.4): an explicit `session_file`
|
|
54
|
+
always wins. A legacy `username` key is used as the session name only when
|
|
55
|
+
no `session_file` is set — configs that relied on username-named sessions
|
|
56
|
+
keep working, but new configs should set `session_file` and omit `username`
|
|
57
|
+
(it plays no part in authentication).
|
|
58
|
+
|
|
48
59
|
|
|
49
60
|
## Quick Start
|
|
50
61
|
|
|
@@ -155,6 +166,13 @@ messages = await tg.get_messages(
|
|
|
155
166
|
)
|
|
156
167
|
```
|
|
157
168
|
|
|
169
|
+
A numeric id resolves only if the session can actually see the group. On a
|
|
170
|
+
cache miss tgdata syncs the account's chat list once and retries — so fresh
|
|
171
|
+
sessions work for groups the account belongs to. If the group still can't be
|
|
172
|
+
found it raises `tgdata.GroupAccessError` (the account is not a member, or
|
|
173
|
+
the id is wrong) instead of Telethon's generic "Could not find the input
|
|
174
|
+
entity" ValueError.
|
|
175
|
+
|
|
158
176
|
### get_messages with start_date parameter
|
|
159
177
|
|
|
160
178
|
```python
|
|
@@ -7,6 +7,9 @@ A production-grade Python library for extracting and processing Telegram group a
|
|
|
7
7
|
# Main class
|
|
8
8
|
from .tgdata import TgData
|
|
9
9
|
|
|
10
|
+
# Errors
|
|
11
|
+
from .message_engine import GroupAccessError
|
|
12
|
+
|
|
10
13
|
# Models
|
|
11
14
|
from .models import (
|
|
12
15
|
MessageData,
|
|
@@ -30,12 +33,15 @@ from .utils import (
|
|
|
30
33
|
# Progress tracking
|
|
31
34
|
from .progress import ProgressTracker
|
|
32
35
|
|
|
33
|
-
__version__ = "0.0.
|
|
36
|
+
__version__ = "0.0.5"
|
|
34
37
|
|
|
35
38
|
__all__ = [
|
|
36
39
|
# Main class
|
|
37
40
|
"TgData",
|
|
38
|
-
|
|
41
|
+
|
|
42
|
+
# Errors
|
|
43
|
+
"GroupAccessError",
|
|
44
|
+
|
|
39
45
|
# Models
|
|
40
46
|
"MessageData",
|
|
41
47
|
"GroupInfo",
|
|
@@ -117,18 +117,38 @@ class ConnectionEngine:
|
|
|
117
117
|
|
|
118
118
|
if telegram_section is None:
|
|
119
119
|
raise ValueError("No [telegram] or [Telegram] section found in config file")
|
|
120
|
-
|
|
120
|
+
|
|
121
|
+
def _unquote(value):
|
|
122
|
+
# INI values are raw text: `username = 'name'` yields the QUOTES as
|
|
123
|
+
# part of the value, and a quoted session name becomes a file
|
|
124
|
+
# literally called 'name'.session on disk. Strip surrounding
|
|
125
|
+
# quotes from every string we read.
|
|
126
|
+
return value.strip().strip("'\"") if isinstance(value, str) else value
|
|
127
|
+
|
|
128
|
+
section = config[telegram_section]
|
|
129
|
+
raw_session = _unquote(section.get('session_file'))
|
|
130
|
+
raw_username = _unquote(section.get('username'))
|
|
131
|
+
|
|
132
|
+
# Session naming precedence: an EXPLICIT session_file always wins — it
|
|
133
|
+
# is the documented home of the credential, and honoring it keeps the
|
|
134
|
+
# session's location independent of the process's working directory.
|
|
135
|
+
# The legacy behavior (username as the session name) applies only when
|
|
136
|
+
# no session_file is configured, so old username-only configs keep
|
|
137
|
+
# finding their existing sessions. 'telegram_session' is the final
|
|
138
|
+
# fallback when neither is set.
|
|
139
|
+
session_name = raw_session or raw_username or 'telegram_session'
|
|
140
|
+
|
|
121
141
|
self._config = ConnectionConfig(
|
|
122
|
-
api_id=
|
|
123
|
-
api_hash=
|
|
124
|
-
session_file=
|
|
125
|
-
phone=
|
|
126
|
-
username=
|
|
142
|
+
api_id=_unquote(section['api_id']),
|
|
143
|
+
api_hash=_unquote(section['api_hash']),
|
|
144
|
+
session_file=session_name,
|
|
145
|
+
phone=_unquote(section.get('phone')),
|
|
146
|
+
username=raw_username,
|
|
127
147
|
max_retries=self.max_retries,
|
|
128
148
|
retry_delay=self.retry_delay,
|
|
129
149
|
exponential_backoff=self.exponential_backoff
|
|
130
150
|
)
|
|
131
|
-
|
|
151
|
+
|
|
132
152
|
return self._config
|
|
133
153
|
|
|
134
154
|
async def get_client(self) -> TelegramClient:
|
|
@@ -173,10 +193,12 @@ class ConnectionEngine:
|
|
|
173
193
|
"""Create and authenticate the primary client once (may be interactive)."""
|
|
174
194
|
config = self._load_config()
|
|
175
195
|
|
|
176
|
-
#
|
|
177
|
-
|
|
196
|
+
# Session naming is resolved ONCE in _load_config (explicit
|
|
197
|
+
# session_file > username > default) — config.session_file IS the
|
|
198
|
+
# resolved name, so the primary client and the pool clients below
|
|
199
|
+
# can never disagree about where the session lives.
|
|
178
200
|
self._primary_client = TelegramClient(
|
|
179
|
-
|
|
201
|
+
config.session_file,
|
|
180
202
|
config.api_id,
|
|
181
203
|
config.api_hash
|
|
182
204
|
)
|
|
@@ -29,6 +29,12 @@ DEFAULT_FETCH_LIMIT = 750
|
|
|
29
29
|
MAX_FLOOD_RETRIES = 3
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
class GroupAccessError(Exception):
|
|
33
|
+
"""The account cannot see this group: it is not a member (or the id is
|
|
34
|
+
wrong). Raised only after a dialog sync ruled out the benign cause —
|
|
35
|
+
a fresh session whose entity cache simply hasn't met the id yet."""
|
|
36
|
+
|
|
37
|
+
|
|
32
38
|
class MessageEngine:
|
|
33
39
|
"""
|
|
34
40
|
Handles all message-related operations.
|
|
@@ -134,7 +140,10 @@ class MessageEngine:
|
|
|
134
140
|
try:
|
|
135
141
|
async with self.connection_engine.session() as client:
|
|
136
142
|
# Get the entity
|
|
137
|
-
|
|
143
|
+
try:
|
|
144
|
+
channel = await client.get_entity(group_id)
|
|
145
|
+
except ValueError:
|
|
146
|
+
channel = await self._entity_after_dialog_sync(client, group_id)
|
|
138
147
|
logger.info(f"Fetching messages from: {channel.title}")
|
|
139
148
|
|
|
140
149
|
# Per-chat context stamped onto every row (provenance / deep links)
|
|
@@ -364,6 +373,25 @@ class MessageEngine:
|
|
|
364
373
|
df['GroupedId'] = df['GroupedId'].astype('Int64')
|
|
365
374
|
return df
|
|
366
375
|
|
|
376
|
+
@staticmethod
|
|
377
|
+
async def _entity_after_dialog_sync(client, group_id):
|
|
378
|
+
"""get_entity said "never seen this id" — an ambiguous error hiding two
|
|
379
|
+
different situations. Telegram sessions can only resolve ids they have
|
|
380
|
+
encountered, so a FRESH session fails even for groups the account IS a
|
|
381
|
+
member of. Sync the chat list (fills the entity cache) and retry once:
|
|
382
|
+
a member resolves and the fetch proceeds as if nothing happened; a
|
|
383
|
+
non-member fails again, and only then is it a real access problem —
|
|
384
|
+
reported as one, instead of Telethon's cache riddle."""
|
|
385
|
+
logger.info(f"Entity {group_id} unknown to this session — syncing dialogs to check membership")
|
|
386
|
+
await client.get_dialogs()
|
|
387
|
+
try:
|
|
388
|
+
return await client.get_entity(group_id)
|
|
389
|
+
except ValueError:
|
|
390
|
+
raise GroupAccessError(
|
|
391
|
+
f"account has no access to group {group_id} — the account is not "
|
|
392
|
+
f"a member (join the group with this account), or the id is wrong"
|
|
393
|
+
) from None
|
|
394
|
+
|
|
367
395
|
@staticmethod
|
|
368
396
|
def _link_base(chat) -> Optional[str]:
|
|
369
397
|
"""Base t.me URL for deep links to this chat's messages (None if not linkable)."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgdata
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: A production-grade Python library for extracting and processing Telegram group and channel messages
|
|
5
5
|
Author: enes kuzucu
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -67,10 +67,21 @@ tgdata supports 1 authentication at the moment.
|
|
|
67
67
|
api_id = 1234566
|
|
68
68
|
api_hash = a24adjfakjdfakjshdflkajsbdflk
|
|
69
69
|
phone = +905064004949 # use full phone number including + and country code
|
|
70
|
-
username = 'powerpuffdude'
|
|
71
70
|
|
|
71
|
+
# Where the Telethon session lives (".session" is appended automatically).
|
|
72
|
+
# Use an ABSOLUTE path — a bare name creates the file in whatever directory
|
|
73
|
+
# the process happens to run from. Do not quote values: INI values are raw
|
|
74
|
+
# text, so quotes become part of the value (tgdata strips them defensively
|
|
75
|
+
# since 0.0.4, but don't rely on it).
|
|
76
|
+
session_file = /absolute/path/to/my_session
|
|
72
77
|
```
|
|
73
78
|
|
|
79
|
+
**Session naming precedence** (since 0.0.4): an explicit `session_file`
|
|
80
|
+
always wins. A legacy `username` key is used as the session name only when
|
|
81
|
+
no `session_file` is set — configs that relied on username-named sessions
|
|
82
|
+
keep working, but new configs should set `session_file` and omit `username`
|
|
83
|
+
(it plays no part in authentication).
|
|
84
|
+
|
|
74
85
|
|
|
75
86
|
## Quick Start
|
|
76
87
|
|
|
@@ -181,6 +192,13 @@ messages = await tg.get_messages(
|
|
|
181
192
|
)
|
|
182
193
|
```
|
|
183
194
|
|
|
195
|
+
A numeric id resolves only if the session can actually see the group. On a
|
|
196
|
+
cache miss tgdata syncs the account's chat list once and retries — so fresh
|
|
197
|
+
sessions work for groups the account belongs to. If the group still can't be
|
|
198
|
+
found it raises `tgdata.GroupAccessError` (the account is not a member, or
|
|
199
|
+
the id is wrong) instead of Telethon's generic "Could not find the input
|
|
200
|
+
entity" ValueError.
|
|
201
|
+
|
|
184
202
|
### get_messages with start_date parameter
|
|
185
203
|
|
|
186
204
|
```python
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|