Added db lookup for replied_to_tweet

This commit is contained in:
jeancf 2023-07-16 12:37:26 +02:00
parent 497d9f3a20
commit e62e5634e0

View File

@ -959,7 +959,7 @@ def main(argv):
tweets = []
out_date_cnt = 0
in_db_cnt = 0
for reply_to, status in timeline:
for replied_to_tweet, status in timeline:
# Extract tweet ID and status ID
tweet_id = status.find('a', class_='tweet-link').get('href').strip('#m')
status_id = tweet_id.split('/')[3]
@ -1113,6 +1113,15 @@ def main(argv):
# Extract posix path of first video file in list
video_file = video_file_list[0].absolute().as_posix()
# Find in database toot id of replied_to_tweet
replied_to_toot = None
if replied_to_tweet is not None:
db.execute("SELECT twoot_id FROM toots WHERE tweet_id=?", replied_to_tweet)
replied_to_toot = db.fetchone()
if replied_to_toot is None:
logging.warning('Replied-to tweet %s not found in database', replied_to_tweet)
# Add dictionary with content of tweet to list
tweet = {
"author": author,
@ -1122,7 +1131,7 @@ def main(argv):
"tweet_text": tweet_text,
"video": video_file,
"photos": photos,
"reply-to": reply_to,
"replied-to-tweet": replied_to_toot,
}
tweets.append(tweet)