Code optimization
This commit is contained in:
pare
89f16e8067
commit
acb3f81d31
S'han modificat 1 arxius amb 6 adicions i 28 eliminacions
34
mastotuit.py
34
mastotuit.py
|
@ -231,7 +231,7 @@ if __name__ == '__main__':
|
|||
try:
|
||||
|
||||
conn = None
|
||||
|
||||
|
||||
conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
||||
|
||||
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
|
||||
|
||||
|
@ -369,33 +371,9 @@ if __name__ == '__main__':
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(insert_line, (link,))
|
||||
cur.execute(sql_insert_link, (link,))
|
||||
|
||||
conn.commit()
|
||||
|
||||
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))
|
||||
cur.execute(sql_insert_ids, (toot_id, tweet.id))
|
||||
|
||||
conn.commit()
|
||||
|
||||
|
|
Loading…
Referencia en una nova incidència