This commit is contained in:
spla 2022-07-16 11:11:26 +02:00
parent 31a4b0a6e2
commit 432528e987
2 changed files with 31 additions and 17 deletions

View file

@ -37,30 +37,44 @@ def get_toot_text(title):
def get_poll(tuit_text):
poll_substring = '[ ]'
poll_options = tuit_text.count(poll_substring)
is_poll = False if poll_options == 0 else True
poll_options = 0
options_lst = []
remain_str = tuit_text.replace('\n', '')
i = poll_options
while (i > 0):
last_option_index = remain_str.rfind('[ ]')
option_str = remain_str[last_option_index+3:].strip()
options_lst.append(option_str)
remain_str = remain_str[:last_option_index]
i-=1
is_poll = False if "input disable" not in entry.summary else True
if is_poll:
poll_substring = """<input disabled="disabled" type="radio" />"""
poll_options = title.count(poll_substring)
remaining_str = title
i = poll_options
while (i > 0):
last_option_index = remaining_str.rfind(poll_substring)
if i == poll_options:
option_str = remaining_str[last_option_index+42:].strip().replace('</p>','')
else:
option_str = remaining_str[last_option_index+42:].strip().replace('<br />','')
options_lst.append(option_str)
remaining_str = remaining_str[:last_option_index]
i-=1
options_lst_copy = options_lst.copy()
options_lst_copy.reverse()
options_lst = options_lst_copy.copy()
tuit_text = remain_str
first_option_index = tuit_text.rfind(options_lst[0])
tuit_text = tuit_text[:first_option_index-1]
return (tuit_text, poll_options, options_lst, is_poll)

View file

@ -1,7 +1,7 @@
wheel>=0.37.0
psycopg2>=2.9.1
psycopg2-binary
feedparser>=6.0.8
bs4>=4.10.0
bs4
Mastodon.py>=1.5.1
tweepy>=4.5.0
filetype>=1.0.8