Moved db lookup to the right section

This commit is contained in:
jeancf 2023-07-16 12:48:26 +02:00
parent e62e5634e0
commit 8bd8aeec29

View File

@ -1113,15 +1113,6 @@ def main(argv):
# Extract posix path of first video file in list # Extract posix path of first video file in list
video_file = video_file_list[0].absolute().as_posix() 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 # Add dictionary with content of tweet to list
tweet = { tweet = {
"author": author, "author": author,
@ -1131,7 +1122,7 @@ def main(argv):
"tweet_text": tweet_text, "tweet_text": tweet_text,
"video": video_file, "video": video_file,
"photos": photos, "photos": photos,
"replied-to-tweet": replied_to_toot, "replied_to_tweet": replied_to_tweet,
} }
tweets.append(tweet) tweets.append(tweet)
@ -1199,6 +1190,16 @@ def main(argv):
TypeError): # Media cannot be uploaded (invalid format, dead link, etc.) TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
pass pass
# Find in database toot id of replied_to_tweet
replied_to_toot = None
if tweet['replied_to_tweet'] is not None:
logging.debug("Seazrching db for replied-to-tweet " + tweet['replied_to_tweet'])
db.execute("SELECT toot_id FROM toots WHERE tweet_id=?", tweet['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)
# Post toot # Post toot
toot = {} toot = {}
try: try: