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_user = feeds_db_user
table = "feeds"
sql = "create table "+table+" (link varchar(300) PRIMARY KEY)"
create_table(db, db_user, table, sql)
table = "id"
sql = "create table "+table+" (toot_id bigint PRIMARY KEY, tweet_id bigint)"

Veure arxiu

@ -311,54 +311,32 @@ if __name__ == '__main__':
link = entry['link']
toot_id = link.rsplit('/')[4]
reply_id = mastodon.status(toot_id).in_reply_to_id
if reply_id != None:
is_reply = True
tweet_id = get_tweet_id(reply_id)
tweet_id = get_tweet_id(toot_id)
if len(entry.links) >= 2:
if tweet_id == 0:
with_images = True
images_list = []
images = len(entry.links) - 1
publish = True
i = 0
while i < images:
reply_id = mastodon.status(toot_id).in_reply_to_id
if reply_id != None:
image_url = entry.links[i+1].href
image_filename = write_image(image_url)
images_list.append(image_filename)
i += 1
is_reply = True
tweet_id = get_tweet_id(reply_id)
###################################################################
# check database if feed is already published
if len(entry.links) >= 2:
try:
with_images = True
images_list = []
images = len(entry.links) - 1
conn = None
i = 0
while i < images:
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()
image_url = entry.links[i+1].href
image_filename = write_image(image_url)
images_list.append(image_filename)
i += 1
###########################################################
@ -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)'
conn = None
@ -389,8 +365,6 @@ if __name__ == '__main__':
cur = conn.cursor()
cur.execute(sql_insert_link, (link,))
cur.execute(sql_insert_ids, (toot_id, tweet.id))
conn.commit()