You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
885 B
31 lines
885 B
from bs4 import BeautifulSoup |
|
|
|
|
|
def parse_outbox( |
|
outbox: dict, |
|
exclude_mentions: bool, |
|
arbitrary_exclude_fn: callable, |
|
|
|
): |
|
posts = outbox['orderedItems'] |
|
|
|
post_list = [] |
|
for post in posts: |
|
obj = post['object'] |
|
# filter out boosts (where obj is a str/url) and posts without content |
|
if isinstance(obj, dict) and 'content' in obj: |
|
cont = obj['content'] |
|
if cont and not arbitrary_exclude_fn(cont): |
|
post_list.append(cont) |
|
|
|
for i, post in enumerate(post_list): |
|
soup = BeautifulSoup(post) |
|
stripped = soup.get_text() |
|
post_list[i] = stripped |
|
|
|
if exclude_mentions: |
|
for i, post in enumerate(post_list): |
|
words = post.split(' ') |
|
post_list[i] = ' '.join([w for w in words if not w.startswith('@')]) |
|
|
|
return '\n\n'.join(post_list)
|
|
|