Giter Site home page Giter Site logo

smirnovv2007 / telegram2rss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zefr0x/python-telegram2rss

0.0 0.0 0.0 100 KB

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

License: GNU Affero General Public License v3.0

Python 100.00%

telegram2rss's Introduction

telegram2rss

Downloads count all Downloads count per month Downloads count per week

PyPI

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/zefr0x/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.

telegram2rss's People

Contributors

zefr0x avatar smirnovv2007 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.