tgdata 0.0.2__tar.gz → 0.0.3__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.2 → tgdata-0.0.3}/PKG-INFO +10 -1
- {tgdata-0.0.2 → tgdata-0.0.3}/README.md +9 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/__init__.py +1 -1
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/message_engine.py +42 -5
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata.egg-info/PKG-INFO +10 -1
- {tgdata-0.0.2 → tgdata-0.0.3}/setup.cfg +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/setup.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/connection_engine.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/models.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/progress.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/__init__.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/my_test.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_00_connection.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_01_list_group_chats.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_02_get_message_count.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_03_get_all_messages.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_04_get_all_messages_in_batches.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_05_with_progress_feature.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_06_polling_simple.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_07_on_new_message_simple.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_07_real_time_event_handler.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_08_batch_callback.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_08_polling.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_10_advanced_features.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_debug_min_id.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_polling_debug.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/smoke_tests/test_username_support.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/tgdata.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata/utils.py +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata.egg-info/SOURCES.txt +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata.egg-info/dependency_links.txt +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/tgdata.egg-info/requires.txt +0 -0
- {tgdata-0.0.2 → tgdata-0.0.3}/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.3
|
|
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
|
|
@@ -273,6 +273,15 @@ messages = await tg.get_messages(
|
|
|
273
273
|
# Note: CSV export drops MediaData; JSON stores a "[Binary data]" placeholder.
|
|
274
274
|
```
|
|
275
275
|
|
|
276
|
+
Downloaded files (modes A and B) are named `<ChatId>_<MessageId>.<ext>` — e.g.
|
|
277
|
+
`1707717812_183019.jpg` — so every file is traceable to its exact message and
|
|
278
|
+
group from the filename alone (and won't collide across groups sharing a folder).
|
|
279
|
+
The precise path is also recorded per row in the `MediaPath` column.
|
|
280
|
+
|
|
281
|
+
**Re-scraping is idempotent:** if a message's file is already on disk, it is
|
|
282
|
+
reused, not re-downloaded — so pulling the same (or an overlapping) range again
|
|
283
|
+
never duplicates files or re-fetches bytes. Each message maps to exactly one file.
|
|
284
|
+
|
|
276
285
|
### Progress Monitoring
|
|
277
286
|
|
|
278
287
|
```python
|
|
@@ -247,6 +247,15 @@ messages = await tg.get_messages(
|
|
|
247
247
|
# Note: CSV export drops MediaData; JSON stores a "[Binary data]" placeholder.
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
+
Downloaded files (modes A and B) are named `<ChatId>_<MessageId>.<ext>` — e.g.
|
|
251
|
+
`1707717812_183019.jpg` — so every file is traceable to its exact message and
|
|
252
|
+
group from the filename alone (and won't collide across groups sharing a folder).
|
|
253
|
+
The precise path is also recorded per row in the `MediaPath` column.
|
|
254
|
+
|
|
255
|
+
**Re-scraping is idempotent:** if a message's file is already on disk, it is
|
|
256
|
+
reused, not re-downloaded — so pulling the same (or an overlapping) range again
|
|
257
|
+
never duplicates files or re-fetches bytes. Each message maps to exactly one file.
|
|
258
|
+
|
|
250
259
|
### Progress Monitoring
|
|
251
260
|
|
|
252
261
|
```python
|
|
@@ -9,6 +9,7 @@ import os
|
|
|
9
9
|
from datetime import datetime, timedelta, timezone
|
|
10
10
|
from typing import Optional, List, Dict, Any, Callable, Iterable, Union
|
|
11
11
|
import pandas as pd
|
|
12
|
+
from telethon import utils as tl_utils
|
|
12
13
|
from telethon.errors import FloodWaitError
|
|
13
14
|
from telethon.tl import types as tl_types
|
|
14
15
|
|
|
@@ -406,6 +407,36 @@ class MessageEngine:
|
|
|
406
407
|
return 'poll'
|
|
407
408
|
return 'other'
|
|
408
409
|
|
|
410
|
+
@staticmethod
|
|
411
|
+
def _media_stem(chat_id: Optional[int], message_id: int) -> str:
|
|
412
|
+
"""
|
|
413
|
+
Deterministic, self-identifying filename stem for a message's media:
|
|
414
|
+
'<chat_id>_<message_id>' (falls back to just the message id if chat_id is
|
|
415
|
+
unknown). Passed WITHOUT an extension — Telethon appends the correct one
|
|
416
|
+
(.jpg/.mp4/...). This makes each file traceable to its exact message/group
|
|
417
|
+
from the filename alone, and unique across groups sharing one folder.
|
|
418
|
+
"""
|
|
419
|
+
return f"{chat_id}_{message_id}" if chat_id is not None else str(message_id)
|
|
420
|
+
|
|
421
|
+
async def _download_or_reuse(self, client, msg, media_dir: str, chat_id: Optional[int]):
|
|
422
|
+
"""
|
|
423
|
+
Download a message's media to '<media_dir>/<chat_id>_<message_id>.<ext>',
|
|
424
|
+
REUSING the file if it already exists (idempotent re-scrape).
|
|
425
|
+
|
|
426
|
+
The extension is predicted up-front with telethon.utils.get_extension (an
|
|
427
|
+
O(1) exists-check, no directory scan), so re-scraping an overlapping range
|
|
428
|
+
neither re-downloads the bytes nor produces Telethon's ' (1)' duplicates —
|
|
429
|
+
each message maps to exactly one file, forever.
|
|
430
|
+
"""
|
|
431
|
+
stem = self._media_stem(chat_id, msg.id)
|
|
432
|
+
ext = tl_utils.get_extension(msg.media) or ''
|
|
433
|
+
target = os.path.join(media_dir, stem + ext)
|
|
434
|
+
if ext and os.path.exists(target):
|
|
435
|
+
logger.debug(f"Media for message {msg.id} already present ({stem}{ext}); reusing")
|
|
436
|
+
return target
|
|
437
|
+
# File doesn't exist yet: Telethon writes exactly to `target` (no rename).
|
|
438
|
+
return await client.download_media(msg, file=target)
|
|
439
|
+
|
|
409
440
|
async def _process_message(self,
|
|
410
441
|
msg,
|
|
411
442
|
client,
|
|
@@ -454,7 +485,9 @@ class MessageEngine:
|
|
|
454
485
|
# (e.g. text-only or a link-preview webpage).
|
|
455
486
|
if media_dir and msg.media is not None:
|
|
456
487
|
try:
|
|
457
|
-
message_data.media_path = await
|
|
488
|
+
message_data.media_path = await self._download_or_reuse(
|
|
489
|
+
client, msg, media_dir, chat_id
|
|
490
|
+
)
|
|
458
491
|
except Exception as e:
|
|
459
492
|
logger.warning(f"Failed to download media for message {msg.id}: {e}")
|
|
460
493
|
|
|
@@ -519,10 +552,14 @@ class MessageEngine:
|
|
|
519
552
|
results[mid] = None
|
|
520
553
|
continue
|
|
521
554
|
try:
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
555
|
+
if output_dir:
|
|
556
|
+
# Named '<chat_id>_<message_id>.<ext>', reused if already present
|
|
557
|
+
results[mid] = await self._download_or_reuse(
|
|
558
|
+
client, msg, output_dir, entity.id
|
|
559
|
+
)
|
|
560
|
+
else:
|
|
561
|
+
# In-memory bytes when no output_dir was given
|
|
562
|
+
results[mid] = await client.download_media(msg, file=bytes)
|
|
526
563
|
except Exception as e:
|
|
527
564
|
logger.warning(f"Failed to download media for message {mid}: {e}")
|
|
528
565
|
results[mid] = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgdata
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
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
|
|
@@ -273,6 +273,15 @@ messages = await tg.get_messages(
|
|
|
273
273
|
# Note: CSV export drops MediaData; JSON stores a "[Binary data]" placeholder.
|
|
274
274
|
```
|
|
275
275
|
|
|
276
|
+
Downloaded files (modes A and B) are named `<ChatId>_<MessageId>.<ext>` — e.g.
|
|
277
|
+
`1707717812_183019.jpg` — so every file is traceable to its exact message and
|
|
278
|
+
group from the filename alone (and won't collide across groups sharing a folder).
|
|
279
|
+
The precise path is also recorded per row in the `MediaPath` column.
|
|
280
|
+
|
|
281
|
+
**Re-scraping is idempotent:** if a message's file is already on disk, it is
|
|
282
|
+
reused, not re-downloaded — so pulling the same (or an overlapping) range again
|
|
283
|
+
never duplicates files or re-fetches bytes. Each message maps to exactly one file.
|
|
284
|
+
|
|
276
285
|
### Progress Monitoring
|
|
277
286
|
|
|
278
287
|
```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
|
|
File without changes
|