mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Added util to parse mastodon toots (very basic, not yet implemented)
This commit is contained in:
parent
40989a54ed
commit
60daa548ca
22
src/sessions/mastodon/compose.py
Normal file
22
src/sessions/mastodon/compose.py
Normal 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]
|
11
src/sessions/mastodon/utils.py
Normal file
11
src/sessions/mastodon/utils.py
Normal 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
|
Loading…
Reference in New Issue
Block a user