telegather 0.2.0__tar.gz → 0.2.2__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.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: telegather
3
+ Version: 0.2.2
4
+ Summary: Export text messages from Telegram channels to CSV.
5
+ Author-email: Endale Shimelis <endale406@gmail.com>
6
+ Requires-Python: >=3.7
7
+ Description-Content-Type: text/markdown
8
+ License-Expression: MIT
9
+ Classifier: Environment :: Console
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ License-File: LICENSE
13
+ Requires-Dist: Telethon>=1.28,<2
14
+ Project-URL: Issues, https://github.com/endale-dev/telegather/issues
15
+ Project-URL: Source, https://github.com/endale-dev/telegather
16
+
17
+ # Telegather
18
+
19
+ Export text messages from a Telegram channel to CSV. Messages are exported newest first, with `id,date,text` columns and line breaks in message text replaced by spaces.
20
+
21
+ ## Install
22
+
23
+ ```text
24
+ pip install --upgrade telegather
25
+ ```
26
+
27
+ Get an API ID and API hash from [my.telegram.org](https://my.telegram.org/). Then run `telegather` in a terminal. Enter the API ID, API hash, channel username, message limit, and output filename when prompted. The API hash input is hidden.
28
+
29
+ On the first run with a new session, Telethon asks for your personal Telegram phone number and a login code. If your account has two-step verification, it also asks for your password. Later runs reuse that login.
30
+
31
+ You can supply options instead of using prompts. For example:
32
+
33
+ ```text
34
+ telegather --channel telegram --limit 10 --output output.csv
35
+ ```
36
+
37
+ The CLI will still prompt for a missing API ID or API hash. You can also set `TELEGRAM_API_ID` and `TELEGRAM_API_HASH` in the environment. Pass `--session NAME` to choose a session name.
38
+
39
+ `--limit` counts messages inspected. Messages without text are skipped. Omit it or pass `0` to inspect the full channel history. The default output file is `msgs.csv`. The destination file is replaced only after an export succeeds.
40
+
41
+ ## Bot session error
42
+
43
+ If you see `The API access for bot users is restricted` or `This session is signed in as a bot`, the saved session belongs to a bot. Telegather cannot export channel history with a bot login. Entering your API ID and hash again will keep using the saved bot session.
44
+
45
+ Start a separate session with your personal Telegram account:
46
+
47
+ ```text
48
+ telegather --session personal_session --channel telegram --limit 10 --output output.csv
49
+ ```
50
+
51
+ Enter your API ID and API hash when prompted, then sign in with your personal phone number and Telegram login code. The API hash from `my.telegram.org` is different from a bot token. You do not need to remove the old bot session.
52
+
53
+ Session files are saved in the directory where you run the command. The default is `telegram_scraper_session.session`. The example above creates `personal_session.session` in that directory. Keep session files private because they contain login data.
54
+
55
+ ## Use from Python
56
+
57
+ ```python
58
+ from telegather import scrape_channel
59
+
60
+ count = scrape_channel(123456, "YOUR_API_HASH", "example", limit=50, output_csv="messages.csv")
61
+ ```
62
+
63
+ In an async program:
64
+
65
+ ```python
66
+ from telegather import scrape_channel_async
67
+
68
+ count = await scrape_channel_async(123456, "YOUR_API_HASH", "example", limit=50)
69
+ ```
70
+
71
+ Both functions return the number of CSV rows written and raise `TelegramScraperError` for export failures. For a separate Python session, pass `session="personal_session"` to either function.
72
+
73
+ ## Development
74
+
75
+ ```text
76
+ python -m pip install -e .
77
+ python -m unittest discover -s tests
78
+ python -m build
79
+ python -m twine check dist/*
80
+ ```
81
+
82
+ The license text is in [LICENSE](LICENSE).
83
+
@@ -0,0 +1,66 @@
1
+ # Telegather
2
+
3
+ Export text messages from a Telegram channel to CSV. Messages are exported newest first, with `id,date,text` columns and line breaks in message text replaced by spaces.
4
+
5
+ ## Install
6
+
7
+ ```text
8
+ pip install --upgrade telegather
9
+ ```
10
+
11
+ Get an API ID and API hash from [my.telegram.org](https://my.telegram.org/). Then run `telegather` in a terminal. Enter the API ID, API hash, channel username, message limit, and output filename when prompted. The API hash input is hidden.
12
+
13
+ On the first run with a new session, Telethon asks for your personal Telegram phone number and a login code. If your account has two-step verification, it also asks for your password. Later runs reuse that login.
14
+
15
+ You can supply options instead of using prompts. For example:
16
+
17
+ ```text
18
+ telegather --channel telegram --limit 10 --output output.csv
19
+ ```
20
+
21
+ The CLI will still prompt for a missing API ID or API hash. You can also set `TELEGRAM_API_ID` and `TELEGRAM_API_HASH` in the environment. Pass `--session NAME` to choose a session name.
22
+
23
+ `--limit` counts messages inspected. Messages without text are skipped. Omit it or pass `0` to inspect the full channel history. The default output file is `msgs.csv`. The destination file is replaced only after an export succeeds.
24
+
25
+ ## Bot session error
26
+
27
+ If you see `The API access for bot users is restricted` or `This session is signed in as a bot`, the saved session belongs to a bot. Telegather cannot export channel history with a bot login. Entering your API ID and hash again will keep using the saved bot session.
28
+
29
+ Start a separate session with your personal Telegram account:
30
+
31
+ ```text
32
+ telegather --session personal_session --channel telegram --limit 10 --output output.csv
33
+ ```
34
+
35
+ Enter your API ID and API hash when prompted, then sign in with your personal phone number and Telegram login code. The API hash from `my.telegram.org` is different from a bot token. You do not need to remove the old bot session.
36
+
37
+ Session files are saved in the directory where you run the command. The default is `telegram_scraper_session.session`. The example above creates `personal_session.session` in that directory. Keep session files private because they contain login data.
38
+
39
+ ## Use from Python
40
+
41
+ ```python
42
+ from telegather import scrape_channel
43
+
44
+ count = scrape_channel(123456, "YOUR_API_HASH", "example", limit=50, output_csv="messages.csv")
45
+ ```
46
+
47
+ In an async program:
48
+
49
+ ```python
50
+ from telegather import scrape_channel_async
51
+
52
+ count = await scrape_channel_async(123456, "YOUR_API_HASH", "example", limit=50)
53
+ ```
54
+
55
+ Both functions return the number of CSV rows written and raise `TelegramScraperError` for export failures. For a separate Python session, pass `session="personal_session"` to either function.
56
+
57
+ ## Development
58
+
59
+ ```text
60
+ python -m pip install -e .
61
+ python -m unittest discover -s tests
62
+ python -m build
63
+ python -m twine check dist/*
64
+ ```
65
+
66
+ The license text is in [LICENSE](LICENSE).
@@ -2,5 +2,5 @@
2
2
 
3
3
  from .scraper import TelegramScraperError, scrape_channel, scrape_channel_async
4
4
 
5
- __version__ = "0.2.0"
5
+ __version__ = "0.2.2"
6
6
  __all__ = ["TelegramScraperError", "scrape_channel", "scrape_channel_async"]
@@ -58,6 +58,11 @@ async def scrape_channel_async(
58
58
  client = TelegramClient(str(session), api_id, api_hash.strip())
59
59
  try:
60
60
  await client.start()
61
+ if await client.is_bot():
62
+ raise TelegramScraperError(
63
+ "This session is signed in as a bot. Use --session with a new name "
64
+ "and sign in with your personal Telegram account."
65
+ )
61
66
  async for message in client.iter_messages(channel.strip(), limit=limit):
62
67
  if message.message:
63
68
  text = message.message.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
@@ -14,6 +14,7 @@ class FakeClient:
14
14
  messages = []
15
15
  failure = None
16
16
  disconnected = False
17
+ bot = False
17
18
  last_instance = None
18
19
 
19
20
  def __init__(self, session, api_id, api_hash):
@@ -26,6 +27,9 @@ class FakeClient:
26
27
  async def disconnect(self):
27
28
  self.disconnected = True
28
29
 
30
+ async def is_bot(self):
31
+ return self.bot
32
+
29
33
  async def iter_messages(self, channel, limit):
30
34
  for message in self.messages[:limit]:
31
35
  if self.failure:
@@ -42,6 +46,7 @@ class ScraperTests(unittest.TestCase):
42
46
  ]
43
47
  FakeClient.failure = None
44
48
  FakeClient.disconnected = False
49
+ FakeClient.bot = False
45
50
  self.directory = tempfile.TemporaryDirectory()
46
51
  self.addCleanup(self.directory.cleanup)
47
52
  self.output = Path(self.directory.name) / "messages.csv"
@@ -72,6 +77,13 @@ class ScraperTests(unittest.TestCase):
72
77
  count = asyncio.run(scrape_channel_async(123, "hash", "channel", None, self.output))
73
78
  self.assertEqual(count, 2)
74
79
 
80
+ def test_bot_session_reports_how_to_sign_in_as_user(self):
81
+ FakeClient.bot = True
82
+ with self.assertRaisesRegex(TelegramScraperError, "signed in as a bot"):
83
+ scrape_channel(123, "hash", "channel", 10, self.output)
84
+ self.assertFalse(self.output.exists())
85
+ self.assertTrue(FakeClient.last_instance.disconnected)
86
+
75
87
  def test_running_loop_guides_to_async_entry_point(self):
76
88
  async def call_sync():
77
89
  with self.assertRaisesRegex(TelegramScraperError, "scrape_channel_async"):
telegather-0.2.0/PKG-INFO DELETED
@@ -1,65 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: telegather
3
- Version: 0.2.0
4
- Summary: Export text messages from Telegram channels to CSV.
5
- Author-email: Endale Shimelis <endale406@gmail.com>
6
- Requires-Python: >=3.7
7
- Description-Content-Type: text/markdown
8
- License-Expression: MIT
9
- Classifier: Environment :: Console
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Programming Language :: Python :: 3
12
- License-File: LICENSE
13
- Requires-Dist: Telethon>=1.28,<2
14
- Project-URL: Issues, https://github.com/endale-dev/telegather/issues
15
- Project-URL: Source, https://github.com/endale-dev/telegather
16
-
17
- # Telegather
18
-
19
- Export text messages from a Telegram channel to CSV. Telegather uses [Telethon](https://docs.telethon.dev/) and keeps the same `id,date,text` columns as earlier releases. Messages are exported newest first, with line breaks in message text replaced by spaces.
20
-
21
- ## Install
22
-
23
- ```bash
24
- pip install telegather
25
- ```
26
-
27
- Get an API ID and API hash from [my.telegram.org](https://my.telegram.org/), then run:
28
-
29
- ```bash
30
- telegather --api-id 123456 --api-hash YOUR_API_HASH --channel example --limit 50 --output messages.csv
31
- ```
32
-
33
- Run `telegather` in a terminal to enter the details through prompts. The API hash prompt hides your input. You can also set `TELEGRAM_API_ID` and `TELEGRAM_API_HASH` in the environment. Telegram may ask you to sign in on the first run. The session is saved as `telegram_scraper_session.session` by default. Use `--session PATH` to choose another location.
34
-
35
- `--limit` counts messages inspected. Messages without text are skipped. Omit it or pass `0` to inspect the full channel history. The default output file is `msgs.csv`. The destination file is replaced only after an export succeeds.
36
-
37
- ## Use from Python
38
-
39
- ```python
40
- from telegather import scrape_channel
41
-
42
- count = scrape_channel(123456, "YOUR_API_HASH", "example", limit=50, output_csv="messages.csv")
43
- ```
44
-
45
- In an async program:
46
-
47
- ```python
48
- from telegather import scrape_channel_async
49
-
50
- count = await scrape_channel_async(123456, "YOUR_API_HASH", "example", limit=50)
51
- ```
52
-
53
- Both functions return the number of CSV rows written and raise `TelegramScraperError` for export failures.
54
-
55
- ## Development
56
-
57
- ```bash
58
- python -m pip install -e .
59
- python -m unittest discover -s tests
60
- python -m build
61
- python -m twine check dist/*
62
- ```
63
-
64
- The license text is in [LICENSE](LICENSE).
65
-
@@ -1,48 +0,0 @@
1
- # Telegather
2
-
3
- Export text messages from a Telegram channel to CSV. Telegather uses [Telethon](https://docs.telethon.dev/) and keeps the same `id,date,text` columns as earlier releases. Messages are exported newest first, with line breaks in message text replaced by spaces.
4
-
5
- ## Install
6
-
7
- ```bash
8
- pip install telegather
9
- ```
10
-
11
- Get an API ID and API hash from [my.telegram.org](https://my.telegram.org/), then run:
12
-
13
- ```bash
14
- telegather --api-id 123456 --api-hash YOUR_API_HASH --channel example --limit 50 --output messages.csv
15
- ```
16
-
17
- Run `telegather` in a terminal to enter the details through prompts. The API hash prompt hides your input. You can also set `TELEGRAM_API_ID` and `TELEGRAM_API_HASH` in the environment. Telegram may ask you to sign in on the first run. The session is saved as `telegram_scraper_session.session` by default. Use `--session PATH` to choose another location.
18
-
19
- `--limit` counts messages inspected. Messages without text are skipped. Omit it or pass `0` to inspect the full channel history. The default output file is `msgs.csv`. The destination file is replaced only after an export succeeds.
20
-
21
- ## Use from Python
22
-
23
- ```python
24
- from telegather import scrape_channel
25
-
26
- count = scrape_channel(123456, "YOUR_API_HASH", "example", limit=50, output_csv="messages.csv")
27
- ```
28
-
29
- In an async program:
30
-
31
- ```python
32
- from telegather import scrape_channel_async
33
-
34
- count = await scrape_channel_async(123456, "YOUR_API_HASH", "example", limit=50)
35
- ```
36
-
37
- Both functions return the number of CSV rows written and raise `TelegramScraperError` for export failures.
38
-
39
- ## Development
40
-
41
- ```bash
42
- python -m pip install -e .
43
- python -m unittest discover -s tests
44
- python -m build
45
- python -m twine check dist/*
46
- ```
47
-
48
- The license text is in [LICENSE](LICENSE).
File without changes
File without changes
File without changes
File without changes