From 842b639af1b86511d5925e6b70b10881f65804db Mon Sep 17 00:00:00 2001 From: spla Date: Sat, 21 Mar 2020 20:26:16 +0100 Subject: [PATCH] Updated mastofeeds.py --- mastofeeds.py | 64 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/mastofeeds.py b/mastofeeds.py index a76f4a6..a6147ca 100644 --- a/mastofeeds.py +++ b/mastofeeds.py @@ -70,70 +70,70 @@ for entry in newsfeeds.entries: try: - conn = None - conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432") + conn = None + conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432") - cur = conn.cursor() + cur = conn.cursor() - cur.execute('select link from feeds where link=(%s)', (link,)) + cur.execute('select link from feeds where link=(%s)', (link,)) - row = cur.fetchone() - if row == None: - publish = 1 - else: - publish = 0 + row = cur.fetchone() + if row == None: + publish = 1 + else: + publish = 0 - cur.close() + cur.close() except (Exception, psycopg2.DatabaseError) as error: - print(error) + print(error) finally: - if conn is not None: + if conn is not None: - conn.close() + conn.close() ########################################################### if publish == 1: - toot_text = str(title)+'\n' - toot_text += str(link) + toot_text = str(title)+'\n' + toot_text += str(link) - print("Tooting...") - print(toot_text) + print("Tooting...") + print(toot_text) - mastodon.status_post(toot_text, in_reply_to_id=None,) + mastodon.status_post(toot_text, in_reply_to_id=None,) ######################################################### - insert_line = 'INSERT INTO feeds(link) VALUES (%s)' + insert_line = 'INSERT INTO feeds(link) VALUES (%s)' - conn = None + conn = None - try: + try: - conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432") + conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432") - cur = conn.cursor() + cur = conn.cursor() - cur.execute(insert_line, (id,)) + cur.execute(insert_line, (id,)) - conn.commit() + conn.commit() - cur.close() + cur.close() - except (Exception, psycopg2.DatabaseError) as error: + except (Exception, psycopg2.DatabaseError) as error: - print(error) + print(error) - finally: + finally: - if conn is not None: + if conn is not None: - conn.close() + conn.close() else: - print("Any new feeds") + print("Any new feeds")