Fixed tweet composing

This commit is contained in:
spla 2021-09-30 18:05:35 +02:00
pare 4a40fa43be
commit 50cb717c23

Veure arxiu

@ -185,25 +185,41 @@ if __name__ == '__main__':
soup = BeautifulSoup(title, 'html.parser')
toot_text = soup.get_text()
sub_str = 'http'
find_link = toot_text.find(sub_str)
if find_link != -1:
toot_text = toot_text[:toot_text.index(sub_str)]
tuit_text = toot_text[:toot_text.index(sub_str)]
else:
tuit_text = toot_text
links_lst = ''
for links in soup.find_all('a'):
links_lst += links.get('href') + ' '
find_tag = links.get('href').find('/tags/')
if find_tag == -1:
links_lst += links.get('href')
toot_text = f'{toot_text} {links_lst}'
if len(links_lst) > 0:
last_text = toot_text[len(tuit_text) + len(links_lst):]
else:
last_text = ''
tuit_text = f'{tuit_text} {links_lst} {last_text}'
print("Tooting...")
print(toot_text)
print(tuit_text)
if not logged_in:
api, logged_in = create_api()
if len(toot_text) < 280:
if len(tuit_text) < 280:
try:
@ -218,11 +234,11 @@ if __name__ == '__main__':
images_id_lst.append(media.media_id)
i += 1
api.update_status(status=toot_text, media_ids=images_id_lst)
api.update_status(status=tuit_text, media_ids=images_id_lst)
else:
api.update_status(toot_text)
api.update_status(tuit_text)
except TweepError as err:
@ -233,13 +249,13 @@ if __name__ == '__main__':
if with_images:
toot_text1 = toot_text[:250].rsplit(' ', 1)[0] + ' (1/2)'
toot_text2 = toot_text[int(len(toot_text1)-6):] + ' (2/2)'
tuit_text1 = tuit_text[:250].rsplit(' ', 1)[0] + ' (1/2)'
tuit_text2 = tuit_text[int(len(tuit_text1)-6):] + ' (2/2)'
else:
toot_text1 = toot_text[:275].rsplit(' ', 1)[0] + ' (1/2)'
toot_text2 = toot_text[int(len(toot_text1)-6):] + ' (2/2)'
tuit_text1 = tuit_text[:275].rsplit(' ', 1)[0] + ' (1/2)'
tuit_text2 = tuit_text[int(len(tuit_text1)-6):] + ' (2/2)'
try:
@ -254,13 +270,13 @@ if __name__ == '__main__':
images_id_lst.append(media.media_id)
i += 1
first_tweet = api.update_status(status=toot_text1)
api.update_status(status=toot_text2, in_reply_to_status_id=first_tweet.id, media_ids=images_id_lst)
first_tweet = api.update_status(status=tuit_text1)
api.update_status(status=tuit_text2, in_reply_to_status_id=first_tweet.id, media_ids=images_id_lst)
else:
first_tweet = api.update_status(toot_text1)
api.update_status(toot_text2, in_reply_to_status_id=first_tweet.id)
first_tweet = api.update_status(tuit_text1)
api.update_status(tuit_text2, in_reply_to_status_id=first_tweet.id)
except TweepError as err: