Skip to main content

A python library to fetch data from public Telegram channels to use them as a python object or RSS feed.

Reason this release was yanked:

Project is no longer maintained and some tests are failing

Project description

telegram2rss

A python library to fetch data from public Telegram channels to use them as a python object or RSS feed.

Installation

From the git repo

git clone https://github.com/zer0-x/python-telegram2rss.git

cd python-telegram2rss

python3 setup.py install

It is recommended to use a virtual environment.

pypi

python3 -m pip install telegram2rss

It is recommended to use a virtual environment.

AUR

Not available yet...

Usage

Fetch to python

import telegram2rss

channel_id = "telegramtips"

channel = telegram2rss.TGChannel(channel_id)

number_of_pages = 3
messages = channel.fetch_to_python(number_of_pages)

# Get some data about the channel after the fetch
print(channel.channel_subscribers_count)
print(channel.channel_title)

# You can also fetch again beginning from the last position
messages2 = channel.fetch_to_python(number_of_pages)

Using a tor or any other proxy

import telegram2rss
import requests

channel_id = "example"

s = requests.Session()
s.proxies = {'http': "socks5://127.0.0.1:9050",
             'https': "socks5://127.0.0.1:9050"}

channel = telegram2rss.TGChannel(channel_id, session_object=s)

Warning Images will be included as links, so they will not be proxied unless you are using a proxy in your RSS reader. Anyway there is a plan to implement a way to download them and included them as bash64 rather then links.

Fetch to RSS

import telegram2rss

channel_id = "example"

channel = telegram2rss.TGChannel("telegramtips")
rss = messages = channel.fetch_to_python(3)

# Decode the text then write it to a rss file:
with open("telegramtips_feed.rss", "w") as f:
    f.writelines(rss.docode()

Some rss readers support reading from a file with a uri like: file:////path/to/telegramtips_feed.rss

You can create a cron job or a systemd timer to run a script every while to update the file.

Creating a flask web app

"""A simple web app to create RSS feed from a telegram channel."""
from flask import Flask
from flask import request

import telegram2rss


app = Flask(__name__)


@app.route('/<channel_id>', methods=['GET'])
def feed(channel_id):
    """Create a channel object then fetch data to rss and return it."""
    channel = telegram2rss.TGChannel(channel_id)
    return channel.fetch_to_rss(int(request.args.get("pages")) or 1).decode()


if __name__ == '__main__':
    app.run()

Now you can use http://127.0.0.1:5000/<channel_id>?pages=<number_or_pages_to_fetch> in you RSS reader.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram2rss-0.1.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

telegram2rss-0.1.1-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file telegram2rss-0.1.1.tar.gz.

File metadata

  • Download URL: telegram2rss-0.1.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.10.0 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

File hashes

Hashes for telegram2rss-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aab73c98b6d76d60aab1e51b07ce8deb0a3a9da3b15596c3b1e484822faf1813
MD5 692300a92e78b34f31e48ef3c758efa6
BLAKE2b-256 fdc510e04715f62fb920cf8cce1027158fda1238a24255cdf8b2d218afbde2ad

See more details on using hashes here.

File details

Details for the file telegram2rss-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: telegram2rss-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.10.0 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

File hashes

Hashes for telegram2rss-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4752ea0076cf113e60681c5f70c7c52ea4a76c94f84064dc71805e77ae88c003
MD5 7cde704f987c2088c05e19dac856d3b8
BLAKE2b-256 66d64f1bb2e7047e066587817f6dcca85c932d8ae1bf08624524fca1cea4c2d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page