Compare commits

..

No commits in common. "24e9bd5691677cd5b8f21e0e46699daba972feb1" and "497d9f3a2069e8dedfabd7498ef81e6e9a473872" have entirely different histories.

View File

@ -173,10 +173,7 @@ Only used by `get_timeline()`.
:param thread_url: url of the first tweet in thread
:return: list of tuples with url of tweet replied-to (or None) and content of tweet
"""
def _get_rest_of_thread(session, headers, nitter_url, thread_url, first_item):
# Add first item to timeline
timeline = [(None, first_item)]
def _get_rest_of_thread(session, headers, nitter_url, thread_url):
logging.debug("Downloading tweets in thread from separate page")
# Download page with thread
url = nitter_url + thread_url
@ -209,19 +206,15 @@ def _get_rest_of_thread(session, headers, nitter_url, thread_url, first_item):
list = after_tweet.find_all('div', class_='timeline-item')
# Build timeline of tuples
timeline = []
previous_tweet_url = thread_url
for item in list:
timeline.append((previous_tweet_url, item))
# Get the url of the tweet
tweet_link_tag = item.find('a', class_='tweet-link')
if tweet_link_tag is not None:
previous_tweet_url = tweet_link_tag.get('href').strip('#m')
else:
previous_tweet_url = None
previous_tweet_url = item.find('a', class_='tweet-link')
if previous_tweet_url is None:
logging.error('Thread tweet is missing link tag')
# return timeline in reverse chronological order
timeline.reverse()
return timeline
@ -296,10 +289,12 @@ def get_timeline(nitter_url):
# Get the url of the tweet
thread_link_tag = item.find('a', class_='tweet-link')
if thread_link_tag is not None:
thread_url = thread_link_tag.get('href').strip('#m')
thread_url = thread_link_tag.get('href')
timeline.append((thread_url, first_item))
# Get the rest of the items of the thread
timeline.extend(_get_rest_of_thread(session, headers, nitter_url, thread_url, first_item))
timeline.extend(_get_rest_of_thread(session, headers, nitter_url, thread_url))
else:
# Ignore other classes
continue
@ -964,7 +959,7 @@ def main(argv):
tweets = []
out_date_cnt = 0
in_db_cnt = 0
for replied_to_tweet, status in timeline:
for reply_to, 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]
@ -1127,7 +1122,7 @@ def main(argv):
"tweet_text": tweet_text,
"video": video_file,
"photos": photos,
"replied_to_tweet": replied_to_tweet,
"reply-to": reply_to,
}
tweets.append(tweet)
@ -1195,25 +1190,13 @@ def main(argv):
TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
pass
# Find in database toot id of replied_to_tweet
replied_to_toot = None
if tweet['replied_to_tweet'] is not None:
logging.debug("Searching db for toot corresponding to 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', tweet['replied_to_tweet'])
else:
logging.debug("toot %s found", replied_to_toot)
# Post toot
toot = {}
try:
if len(media_ids) == 0:
toot = mastodon.status_post(tweet['tweet_text'], replied_to_toot)
toot = mastodon.status_post(tweet['tweet_text'])
else:
toot = mastodon.status_post(tweet['tweet_text'], replied_to_toot, media_ids=media_ids)
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
except MastodonAPIError:
# Assuming this is an: