Code optimization

This commit is contained in:
spla 2021-10-09 13:30:18 +02:00
pare 89f16e8067
commit acb3f81d31

Veure arxiu

@ -231,7 +231,7 @@ if __name__ == '__main__':
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()
@ -359,7 +359,9 @@ if __name__ == '__main__':
######################################################### #########################################################
insert_line = 'INSERT INTO feeds(link) VALUES (%s)' sql_insert_link = 'INSERT INTO feeds(link) VALUES (%s)'
sql_insert_ids = 'INSERT INTO id(toot_id, tweet_id) VALUES (%s,%s)'
conn = None conn = None
@ -369,33 +371,9 @@ if __name__ == '__main__':
cur = conn.cursor() cur = conn.cursor()
cur.execute(insert_line, (link,)) cur.execute(sql_insert_link, (link,))
conn.commit() cur.execute(sql_insert_ids, (toot_id, tweet.id))
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
insert_line = 'INSERT INTO id(toot_id, tweet_id) VALUES (%s,%s)'
conn = None
try:
conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()
cur.execute(insert_line, (toot_id, tweet.id))
conn.commit() conn.commit()