-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ea788a
commit afb0d6f
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
worker: python3 rss.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# RSS Feed Telegram Bot | ||
A bot to post messages to Telegram Groups or Channels from rss feed. | ||
|
||
### Configuration | ||
- Edit the [rss.py](./rss.py) as your needs. | ||
- Edit values in [rss.py](./rss.py) or set it in Environment Variables. If you are using Environment Variables, Add a `ENV` var to anything to enable Environment Variables Mode. | ||
|
||
### Configuration Values | ||
- `APP_ID` - Get it from [my.telegram.org](https://my.telegram.org/apps) | ||
- `API_HASH` - Get it from [my.telegram.org](https://my.telegram.org/apps) | ||
- `BOT_TOKEN` - Get it by creating a Telegram bot on [BotFather](https://t.me/BotFather) | ||
- `FEED_URL` - URL of RSS Feed | ||
- `LOG_CHANNEL` - ID of the Telegram Channel where messages are to be posted. | ||
- `INTERVAL` - Checking Interval in seconds. (optional) | ||
- `MAX_INSTANCES` - Max instances to be used while checking rss feed. (optional) | ||
|
||
### Deployment | ||
- Install requirements from [requirements.txt](./requirements.txt) | ||
``` | ||
pip3 install requirements.txt | ||
``` | ||
- Deploy | ||
``` | ||
python3 rss.py | ||
``` | ||
|
||
## Copyright & License | ||
- Copyright (©) 2021 by [Adnan Ahmad](https://github.com/viperadnan-git) | ||
- Licensed under the terms of the [GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pyrogram==1.0.1 | ||
feedparser | ||
apscheduler | ||
pickledb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import pickledb # You can use any other database too. Use SQL if you are using Heroku Postgres. | ||
import feedparser | ||
from time import sleep, time | ||
from pyrogram import Client, filters | ||
from pyrogram.errors import FloodWait | ||
from apscheduler.schedulers.background import BackgroundScheduler | ||
|
||
|
||
api_id = "" # Get it from my.telegram.org | ||
api_hash = "" # Get it from my.telegram.org | ||
feed_url = "" # RSS Feed URL of the site. | ||
bot_token = "" # Get it by creating a bot on https://t.me/botfather | ||
log_channel = "" # Telegram Channel ID where the bot is added and have write permission. You can use group ID too. | ||
check_interval = 5 # Check Interval in seconds. | ||
max_instances = 5 # Max parallel instance to be used. | ||
if os.environ.get("ENV"): # Add a ENV in Environment Variables if you wanna configure the bot via env vars. | ||
api_id = os.environ.get("APP_ID") | ||
api_hash = os.environ.get("API_HASH") | ||
feed_url = os.environ.get("FEED_URL") | ||
bot_token = os.environ.get("BOT_TOKEN") | ||
log_channel = int(os.environ.get("LOG_CHANNEL", None)) | ||
check_interval = int(os.environ.get("INTERVAL", 5)) | ||
max_instances = int(os.environ.get("MAX_INSTANCES", 5)) | ||
|
||
db = pickledb.load('rss.db', True) | ||
if db.get("feed_url") == None: | ||
db.set("feed_url", "*") | ||
app = Client("rss-bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token) | ||
|
||
def check_feed(): | ||
FEED = feedparser.parse(feed_url) | ||
entry = FEED.entries[0] | ||
if entry.id != db.get("feed_url"): | ||
|
||
# ↓ Edit this message as your needs. | ||
message = f"**{entry.title}**\n```{entry.link}```" | ||
|
||
try: | ||
app.send_message(log_channel, message) | ||
db.set("feed_url", entry.id) | ||
except FloodWait as e: | ||
print(f"FloodWait: {e.x} seconds") | ||
sleep(e.x) | ||
except Exception as e: | ||
print(e) | ||
else: | ||
print(f"Checked RSS FEED: {entry.id}") | ||
|
||
|
||
|
||
scheduler = BackgroundScheduler() | ||
scheduler.add_job(check_feed, "interval", seconds=check_interval, max_instances=max_instances) | ||
scheduler.start() | ||
app.run() |