Optimized code (-22 lines) and removed unneeded table feeds

This commit is contained in:
spla 2021-10-15 14:02:11 +02:00
pare 979d24984b
commit af5a373bcd
S'han modificat 2 arxius amb 17 adicions i 46 eliminacions

Veure arxiu

@ -135,9 +135,6 @@ print("Creating table...")
db = feeds_db db = feeds_db
db_user = feeds_db_user db_user = feeds_db_user
table = "feeds"
sql = "create table "+table+" (link varchar(300) PRIMARY KEY)"
create_table(db, db_user, table, sql)
table = "id" table = "id"
sql = "create table "+table+" (toot_id bigint PRIMARY KEY, tweet_id bigint)" sql = "create table "+table+" (toot_id bigint PRIMARY KEY, tweet_id bigint)"

Veure arxiu

@ -311,6 +311,13 @@ if __name__ == '__main__':
link = entry['link'] link = entry['link']
toot_id = link.rsplit('/')[4] toot_id = link.rsplit('/')[4]
tweet_id = get_tweet_id(toot_id)
if tweet_id == 0:
publish = True
reply_id = mastodon.status(toot_id).in_reply_to_id reply_id = mastodon.status(toot_id).in_reply_to_id
if reply_id != None: if reply_id != None:
@ -331,35 +338,6 @@ if __name__ == '__main__':
images_list.append(image_filename) images_list.append(image_filename)
i += 1 i += 1
###################################################################
# check database if feed is already published
try:
conn = None
conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()
cur.execute('select link from feeds where link=(%s)', (link,))
row = cur.fetchone()
if row == None:
publish = True
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
########################################################### ###########################################################
if publish: if publish:
@ -377,8 +355,6 @@ if __name__ == '__main__':
######################################################### #########################################################
sql_insert_link = 'INSERT INTO feeds(link) VALUES (%s)'
sql_insert_ids = 'INSERT INTO id(toot_id, tweet_id) VALUES (%s,%s)' sql_insert_ids = 'INSERT INTO id(toot_id, tweet_id) VALUES (%s,%s)'
conn = None conn = None
@ -389,8 +365,6 @@ if __name__ == '__main__':
cur = conn.cursor() cur = conn.cursor()
cur.execute(sql_insert_link, (link,))
cur.execute(sql_insert_ids, (toot_id, tweet.id)) cur.execute(sql_insert_ids, (toot_id, tweet.id))
conn.commit() conn.commit()