From 975a752a1085788965afa0755e4f8368e9e5d604 Mon Sep 17 00:00:00 2001 From: spla Date: Sat, 15 May 2021 11:19:08 +0200 Subject: [PATCH] Handle feedparser exception --- mastofeeds.py | 17 ++++++++++++----- setup.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mastofeeds.py b/mastofeeds.py index 758bbe4..d4d0d2c 100644 --- a/mastofeeds.py +++ b/mastofeeds.py @@ -3,10 +3,7 @@ import feedparser from mastodon import Mastodon import psycopg2 import sys - -############################################################################### -# INITIALISATION -############################################################################### +import time # Returns the parameter from the specified file def get_parameter( parameter, file_path ): @@ -61,7 +58,15 @@ if __name__ == '__main__': publish = 0 - newsfeeds = feedparser.parse(feeds_url) + try: + + newsfeeds = feedparser.parse(feeds_url) + print(newsfeeds.status) + + except: + + print(newsfeeds.status) + sys.exit(0) for entry in newsfeeds.entries: @@ -111,6 +116,8 @@ if __name__ == '__main__': mastodon.status_post(toot_text, in_reply_to_id=None,) + time.sleep(2) + ######################################################### insert_line = 'INSERT INTO feeds(id, link) VALUES (%s, %s)' diff --git a/setup.py b/setup.py index 6d33c3e..8e6303d 100644 --- a/setup.py +++ b/setup.py @@ -124,7 +124,7 @@ def log_in(): if os.path.exists("app_clientcred.txt"): print("Removing app_clientcred.txt temp file..") os.remove("app_clientcred.txt") - if os.path.exists("app_usercred.txt"): + if os.path.exists("app_usercred.txt"): print("Removing app_usercred.txt temp file..") os.remove("app_usercred.txt") print("Secrets setup done!\n")