rss 디스코드 새글 보내기 파이썬
import requests
import feedparser
webhook_url = 'https://'
# 디스코드 웹훅주소
rss_url = 'https://'
# rss주소
def send_to_discord(message):
payload = {'content': message}
requests.post(webhook_url, json=payload)
def get_last_entry():
try:
with open('last_posted.txt', 'r') as file:
return file.read().strip()
except FileNotFoundError:
return None
def update_last_entry(link):
with open('last_posted.txt', 'w') as file:
file.write(link)
def check_rss_feed():
feed = feedparser.parse(rss_url)
latest_entry = feed.entries[0] #글순서 rss 첫번째 글1개 전송
last_posted_entry = get_last_entry()
if latest_entry.link != last_posted_entry:
send_to_discord(f"💬: {latest_entry.title} - {latest_entry.link}")
update_last_entry(latest_entry.link)
check_rss_feed()
![](https://vip-url.com/wp-content/uploads/2024/07/Screenshot-2024-07-15-at-18.28.49-1024x460.jpg)