Created
May 2, 2023 05:52
-
-
Save gyurisc/a9d7d69a23a523a014719b03429559b6 to your computer and use it in GitHub Desktop.
Feed parser gist script that runs on every 5 mins
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 | |
import time | |
def parse_feed(feed_url): | |
rss_feed = feedparser.parse(feed_url) | |
return rss_feed | |
def get_latest_entries(rss_feed, last_updated): | |
new_entries = [] | |
for entry in rss_feed.entries: | |
entry_time = time.mktime(entry.published_parsed) | |
if entry_time > last_updated: | |
new_entries.append(entry) | |
return new_entries | |
def main(): | |
feed_url = "https://example.com/rss-feed" # Replace with your desired RSS feed URL | |
update_interval = 5 * 60 # 5 minutes in seconds | |
last_updated = 0 | |
while True: | |
print("Checking for new RSS entries...") | |
rss_feed = parse_feed(feed_url) | |
if last_updated == 0: | |
print("Initializing...") | |
last_updated = time.mktime(rss_feed.feed.updated_parsed) | |
else: | |
new_entries = get_latest_entries(rss_feed, last_updated) | |
if new_entries: | |
print("New entries found:") | |
for entry in new_entries: | |
print("{} - {}".format(entry.title, entry.link)) | |
last_updated = time.mktime(rss_feed.feed.updated_parsed) | |
else: | |
print("No new entries found.") | |
print("Waiting for {} minutes...".format(update_interval/60)) | |
time.sleep(update_interval) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment