Skip to content

Instantly share code, notes, and snippets.

@devjorgecastro
Created February 4, 2023 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devjorgecastro/843dfcf5ca3defb798f5b5ef5cab4d3c to your computer and use it in GitHub Desktop.
Save devjorgecastro/843dfcf5ca3defb798f5b5ef5cab4d3c to your computer and use it in GitHub Desktop.
RSS reader in Python for Discord
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)
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