tgc


Nametgc JSON
Version 1.1.0 PyPI version JSON
download
home_page
SummaryTelegram Channel Backup Crawler
upload_time2023-07-15 17:21:21
maintainer
docs_urlNone
author
requires_python>=3.10
licenseMIT License Copyright (c) 2022 Hykilpikonna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords telegram backup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TelegramBackup

This is the Telegram adapter for [tg-blog](https://github.com/one-among-us/tg-blog), a front-end for displaying telegram (or any compatible) channel data as an interactive web page.

#### Motivation

Telegram has become increasingly fragile, recently [revoking usernames for inactive channels](https://t.me/tginfoen/1471), and often randomly banning regular users misclassified as spam. During the username revoking, many channels of deceased individuals have been remove from public space, no longer accessible using `t.me` links. This tool helps to maintain Telegram channel data in case of an accidental event, and also to publicly display inactive channels that have been revoked.

#### Demos / Examples

* You can add this to your blog so that it syncs with your telegram channel (e.g. [Azalea's Blog](https://aza.moe/life)).
* You can also use this to back up and display another person's channel (e.g. [donotexist_A's backup on One Among Us](https://www.one-among.us/profile/donotexist_A/backup/telegram)).

## Usage

### Installation

First, install Python `>= 3.11`. Then, run `pip install tgc`

Then, to support video/animation/sticker conversion, you have to install the following non-python dependencies:

1. Install Node 19.2 and yarn 1.22
2. `yarn global add puppeteer-lottie-cli`
3. Install `ffmpeg` using your system package manager

### Mode 1: Convert Telegram Export

If you only need a one-time export, you can use mode 1. To do this, you first need to export a channel using [tdesktop](https://github.com/telegramdesktop/tdesktop).

To convert an export file into a format supported by [tg-blog](https://github.com/one-among-us/tg-blog), you can run `tgce <export path>`

### Mode 2: Crawl Channel using MTProto API

If you have the permission to add a bot account to a channel, or invite a self-bot account, you can use the MTProto crawler for automatic incremental export updates. (**Please, do not log into your own Telegram account for crawling**, there's a very high chance of being mis-classified as spam and get banned)

Using this method, it can automatically update the channel backup incrementally, and the information will be more complete. However, it is more difficult to set up than mode 1.

#### Setup API Keys

1. Obtain `api_id` and `api_hash` by creating your Telegram application ([Official Guide](https://core.telegram.org/api/obtaining_api_id#obtaining-api-id))
    1. Log into https://my.telegram.org/apps
    2. Fill out the form to create an application
    3. Or, if you want to go against Telegram's EULA for your convenience, you can leave them blank to use Telegram's official client's API hash at your own risk.
2. Choose which type of account to log in:
    1. **Bot account**: Create a bot using the [@BotFather](https://t.me/BotFather) bot.
    2. **Self-bot account**: Leave `bot_token` blank, it will prompt you to login. You should only use a self-bot when you're not the admin of the channel (because inviting a bot requires admin access).
3. Fill in the tokens in `~/.config/tgc/config.toml` as shown below

```toml
# Telegram API id & hash
api_id = 10000000
api_hash = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

# Telegram bot token (leave blank to log into self-bot account)
bot_token = "0000000000:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
```

After setting up the keys, you can proceed to setting up the channel:

#### Setup Channels to be Crawled

1. Either invite your bot to the channel or join the channel on your self-bot account
2. Forward a channel message to [@RawDataBot](https://t.me/RawDataBot) to obtain the channel ID. (You'll see a JSON response, and you can find the ID from the `forward_from_chat` field)
3. Fill in the channel info in `~/.config/tgc/config.toml` as shown below

```toml
# One export entry in a list of exports
[[exports]]
chat_id = -1001191767119    # Telegram channel chat id
path = "exports/hykilp"     # Output Path
```

After all setup is complete, you can proceed to running the crawler.

#### Running the Crawler

Simply run the `tgc` command.

## Additional Config

You can set additional configuration for each export entry like below:

| Field           | Description                                   | Type  |
|-----------------|-----------------------------------------------|-------|
| `size_limit_mb` | Limit downloaded file size (skip large files) | float |

### RSS Feed Generation

If you want to generate RSS feed, you can add the following under the export entry:

```toml
[[exports]]
chat_id = -1001191767119    # Telegram channel chat id
path = "exports/hykilp"     # Output Path

[exports.rss]
title = "小桂桂的回忆录 📒"
link = "https://aza.moe/life"
description = "「我们所经历的每个平凡的日常,也许就是连续发生的奇迹」"
language = "zh-cn"
image_url = "https://aza.moe/meru_256px.png"
```

## Automatic Updates using GitHub Actions

If you want to automatically backup/sync telegram channel data using GitHub Actions, you can do this.

1. Create your `config.toml`
2. Make a fork of https://github.com/hykilpikonna/blog-data
3. In GitHub's Settings tab, create a secret called `TGC_CONFIG`, and paste your `config.toml` there.
4. Remember to set a `size_limit_mb` to below 100 so that git lfs won't warn you for pushing large files.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tgc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "telegram,backup",
    "author": "",
    "author_email": "Azalea Gui <me@hydev.org>",
    "download_url": "https://files.pythonhosted.org/packages/4e/2c/c82c0ee7f63df8eff2f1b0f1d05cc56bb72ab9336411e004dfc611f26f9c/tgc-1.1.0.tar.gz",
    "platform": null,
    "description": "# TelegramBackup\n\nThis is the Telegram adapter for [tg-blog](https://github.com/one-among-us/tg-blog), a front-end for displaying telegram (or any compatible) channel data as an interactive web page.\n\n#### Motivation\n\nTelegram has become increasingly fragile, recently [revoking usernames for inactive channels](https://t.me/tginfoen/1471), and often randomly banning regular users misclassified as spam. During the username revoking, many channels of deceased individuals have been remove from public space, no longer accessible using `t.me` links. This tool helps to maintain Telegram channel data in case of an accidental event, and also to publicly display inactive channels that have been revoked.\n\n#### Demos / Examples\n\n* You can add this to your blog so that it syncs with your telegram channel (e.g. [Azalea's Blog](https://aza.moe/life)).\n* You can also use this to back up and display another person's channel (e.g. [donotexist_A's backup on One Among Us](https://www.one-among.us/profile/donotexist_A/backup/telegram)).\n\n## Usage\n\n### Installation\n\nFirst, install Python `>= 3.11`. Then, run `pip install tgc`\n\nThen, to support video/animation/sticker conversion, you have to install the following non-python dependencies:\n\n1. Install Node 19.2 and yarn 1.22\n2. `yarn global add puppeteer-lottie-cli`\n3. Install `ffmpeg` using your system package manager\n\n### Mode 1: Convert Telegram Export\n\nIf you only need a one-time export, you can use mode 1. To do this, you first need to export a channel using [tdesktop](https://github.com/telegramdesktop/tdesktop).\n\nTo convert an export file into a format supported by [tg-blog](https://github.com/one-among-us/tg-blog), you can run `tgce <export path>`\n\n### Mode 2: Crawl Channel using MTProto API\n\nIf you have the permission to add a bot account to a channel, or invite a self-bot account, you can use the MTProto crawler for automatic incremental export updates. (**Please, do not log into your own Telegram account for crawling**, there's a very high chance of being mis-classified as spam and get banned)\n\nUsing this method, it can automatically update the channel backup incrementally, and the information will be more complete. However, it is more difficult to set up than mode 1.\n\n#### Setup API Keys\n\n1. Obtain `api_id` and `api_hash` by creating your Telegram application ([Official Guide](https://core.telegram.org/api/obtaining_api_id#obtaining-api-id))\n    1. Log into https://my.telegram.org/apps\n    2. Fill out the form to create an application\n    3. Or, if you want to go against Telegram's EULA for your convenience, you can leave them blank to use Telegram's official client's API hash at your own risk.\n2. Choose which type of account to log in:\n    1. **Bot account**: Create a bot using the [@BotFather](https://t.me/BotFather) bot.\n    2. **Self-bot account**: Leave `bot_token` blank, it will prompt you to login. You should only use a self-bot when you're not the admin of the channel (because inviting a bot requires admin access).\n3. Fill in the tokens in `~/.config/tgc/config.toml` as shown below\n\n```toml\n# Telegram API id & hash\napi_id = 10000000\napi_hash = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n\n# Telegram bot token (leave blank to log into self-bot account)\nbot_token = \"0000000000:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n```\n\nAfter setting up the keys, you can proceed to setting up the channel:\n\n#### Setup Channels to be Crawled\n\n1. Either invite your bot to the channel or join the channel on your self-bot account\n2. Forward a channel message to [@RawDataBot](https://t.me/RawDataBot) to obtain the channel ID. (You'll see a JSON response, and you can find the ID from the `forward_from_chat` field)\n3. Fill in the channel info in `~/.config/tgc/config.toml` as shown below\n\n```toml\n# One export entry in a list of exports\n[[exports]]\nchat_id = -1001191767119    # Telegram channel chat id\npath = \"exports/hykilp\"     # Output Path\n```\n\nAfter all setup is complete, you can proceed to running the crawler.\n\n#### Running the Crawler\n\nSimply run the `tgc` command.\n\n## Additional Config\n\nYou can set additional configuration for each export entry like below:\n\n| Field           | Description                                   | Type  |\n|-----------------|-----------------------------------------------|-------|\n| `size_limit_mb` | Limit downloaded file size (skip large files) | float |\n\n### RSS Feed Generation\n\nIf you want to generate RSS feed, you can add the following under the export entry:\n\n```toml\n[[exports]]\nchat_id = -1001191767119    # Telegram channel chat id\npath = \"exports/hykilp\"     # Output Path\n\n[exports.rss]\ntitle = \"\u5c0f\u6842\u6842\u7684\u56de\u5fc6\u5f55 \ud83d\udcd2\"\nlink = \"https://aza.moe/life\"\ndescription = \"\u300c\u6211\u4eec\u6240\u7ecf\u5386\u7684\u6bcf\u4e2a\u5e73\u51e1\u7684\u65e5\u5e38\uff0c\u4e5f\u8bb8\u5c31\u662f\u8fde\u7eed\u53d1\u751f\u7684\u5947\u8ff9\u300d\"\nlanguage = \"zh-cn\"\nimage_url = \"https://aza.moe/meru_256px.png\"\n```\n\n## Automatic Updates using GitHub Actions\n\nIf you want to automatically backup/sync telegram channel data using GitHub Actions, you can do this.\n\n1. Create your `config.toml`\n2. Make a fork of https://github.com/hykilpikonna/blog-data\n3. In GitHub's Settings tab, create a secret called `TGC_CONFIG`, and paste your `config.toml` there.\n4. Remember to set a `size_limit_mb` to below 100 so that git lfs won't warn you for pushing large files.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 Hykilpikonna  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Telegram Channel Backup Crawler",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/one-among-us/TelegramBackup"
    },
    "split_keywords": [
        "telegram",
        "backup"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "493349b547c8a68ba7de5c1aa647e641726a7fe36fff0155e7913323bfc0fd82",
                "md5": "69c5773473438c714c47059c7764dbc3",
                "sha256": "08f1537f25e3bd67a9a41721746c1a092ba000a71d1baf70bc1ac6ff46b40b89"
            },
            "downloads": -1,
            "filename": "tgc-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "69c5773473438c714c47059c7764dbc3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20615,
            "upload_time": "2023-07-15T17:21:20",
            "upload_time_iso_8601": "2023-07-15T17:21:20.152236Z",
            "url": "https://files.pythonhosted.org/packages/49/33/49b547c8a68ba7de5c1aa647e641726a7fe36fff0155e7913323bfc0fd82/tgc-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e2cc82c0ee7f63df8eff2f1b0f1d05cc56bb72ab9336411e004dfc611f26f9c",
                "md5": "0d0d618993d6f19c0a701b24be864e1b",
                "sha256": "4797340f673cff65d6856bb4e88fea7cbe67c5fc7c2fc99e841c52b53397200d"
            },
            "downloads": -1,
            "filename": "tgc-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0d0d618993d6f19c0a701b24be864e1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 37682,
            "upload_time": "2023-07-15T17:21:21",
            "upload_time_iso_8601": "2023-07-15T17:21:21.569497Z",
            "url": "https://files.pythonhosted.org/packages/4e/2c/c82c0ee7f63df8eff2f1b0f1d05cc56bb72ab9336411e004dfc611f26f9c/tgc-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-15 17:21:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "one-among-us",
    "github_project": "TelegramBackup",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tgc"
}
        
Elapsed time: 0.08772s