Created
February 4, 2023 19:49
-
-
Save devjorgecastro/843dfcf5ca3defb798f5b5ef5cab4d3c to your computer and use it in GitHub Desktop.
RSS reader in Python for Discord
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
import requests | |
class DiscordNews: | |
def __init__(self, webhook, username, avatar_url, feed): | |
self.webhook = webhook | |
self.username = username | |
self.avatar_url = avatar_url | |
self.feed = feed | |
def prepare_and_notify(self): | |
for entry in self.feed.entries: | |
self.__notify_to_discord_channel(entry) | |
def __notify_to_discord_channel(self, data): | |
headers = { "Content-Type": "application/json" } | |
content = f''' | |
New Post: **{data.title}** | |
Autor: {data.author} | |
{data.link} | |
''' | |
payload = { | |
"username": self.username, | |
"content": content, | |
"avatar_url": self.avatar_url | |
} | |
return requests.post(url=self.webhook, headers=headers, json=payload) |
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
import feedparser | |
from discord_module.DiscordNews import DiscordNews | |
webhook = "https://discord.com/webhooks/{webhook_id}/{webhook_token}" #Replace with your webhook | |
username = "Android News" | |
avatar_url = "https://source.android.com/static/docs/setup/images/Android_symbol_green_RGB.png" | |
feed_url = "https://medium.com/feed/@devjorgecastro" | |
feed = feedparser.parse(feed_url) | |
discord = DiscordNews(webhook, username, avatar_url, feed) | |
discord.prepare_and_notify() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment