Updated mastofeeds.py

This commit is contained in:
spla 2020-03-21 20:26:16 +01:00
pare 0f16738f03
commit 842b639af1

Veure arxiu

@ -70,70 +70,70 @@ for entry in newsfeeds.entries:
try: try:
conn = None conn = None
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('select link from feeds where link=(%s)', (link,)) cur.execute('select link from feeds where link=(%s)', (link,))
row = cur.fetchone() row = cur.fetchone()
if row == None: if row == None:
publish = 1 publish = 1
else: else:
publish = 0 publish = 0
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()
########################################################### ###########################################################
if publish == 1: if publish == 1:
toot_text = str(title)+'\n' toot_text = str(title)+'\n'
toot_text += str(link) toot_text += str(link)
print("Tooting...") print("Tooting...")
print(toot_text) 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: else:
print("Any new feeds") print("Any new feeds")