Added util to parse mastodon toots (very basic, not yet implemented)

This commit is contained in:
Manuel Cortez 2022-11-07 17:13:03 -06:00
parent 40989a54ed
commit 60daa548ca
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import arrow
from . import utils
def compose_toot(toot, db, relative_times, show_screen_names):
if show_screen_names == False:
user = toot.account.get("display_name")
else:
user = toot.account.get("acct")
original_date = arrow.get(toot.created_at)
if relative_times:
ts = original_date.humanize(locale="es")
else:
ts = original_date.shift(hours=db["utc_offset"]).format(_("dddd, MMMM D, YYYY H:m:s"), locale="es")
if toot.reblog != None:
text = "RT @{}: {}".format(toot.reblog.account.acct, utils.html_filter(toot.reblog.content))
else:
text = utils.html_filter(toot.content)
source = toot.get("application", "")
if source != "":
source = source.get("name", "")
return [user+", ", text, ts+", ", source]

View File

@ -0,0 +1,11 @@
from html.parser import HTMLParser
class HTMLFilter(HTMLParser):
text = ""
def handle_data(self, data):
self.text += data
def html_filter(data):
f = HTMLFilter()
f.feed(data)
return f.text