Optimized code (-22 lines) and removed unneeded table feeds
This commit is contained in:
pare
979d24984b
commit
af5a373bcd
S'han modificat 2 arxius amb 17 adicions i 46 eliminacions
|
@ -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)"
|
||||||
|
|
60
mastotuit.py
60
mastotuit.py
|
@ -311,54 +311,32 @@ if __name__ == '__main__':
|
||||||
link = entry['link']
|
link = entry['link']
|
||||||
|
|
||||||
toot_id = link.rsplit('/')[4]
|
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(toot_id)
|
||||||
tweet_id = get_tweet_id(reply_id)
|
|
||||||
|
|
||||||
if len(entry.links) >= 2:
|
if tweet_id == 0:
|
||||||
|
|
||||||
with_images = True
|
publish = True
|
||||||
images_list = []
|
|
||||||
images = len(entry.links) - 1
|
|
||||||
|
|
||||||
i = 0
|
reply_id = mastodon.status(toot_id).in_reply_to_id
|
||||||
while i < images:
|
if reply_id != None:
|
||||||
|
|
||||||
image_url = entry.links[i+1].href
|
is_reply = True
|
||||||
image_filename = write_image(image_url)
|
tweet_id = get_tweet_id(reply_id)
|
||||||
images_list.append(image_filename)
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
###################################################################
|
if len(entry.links) >= 2:
|
||||||
# check database if feed is already published
|
|
||||||
|
|
||||||
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")
|
image_url = entry.links[i+1].href
|
||||||
|
image_filename = write_image(image_url)
|
||||||
cur = conn.cursor()
|
images_list.append(image_filename)
|
||||||
|
i += 1
|
||||||
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()
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
|
Loading…
Referencia en una nova incidència