finish masto-fedi implementation

workspace
Brendan Howell 4 years ago
parent fa9ae8668e
commit b7498d1207

@ -287,14 +287,68 @@ class PublicRelations(Bureau):
toot_id = self.get_toot_id(shortcode) toot_id = self.get_toot_id(shortcode)
self.masto.status_favorite(toot_id) self.masto.status_favorite(toot_id)
@add_command("tootpic", "Post a Document Camera Image to the Fediverse") @add_command("marp", "Reply to a toot")
def toot_pic(self): def reply_toot(self, data):
"""
Reply to a toot with the image under the document camera.
"""
shortcode, _ = data.split(".")
toot_id = self.get_toot_id(shortcode)
self.toot_pic(reply_to=toot_id)
@add_command("toot", "Post a Document Camera Image to the Fediverse")
def toot_pic(self, reply_to=None):
""" """
Takes a photograph using the document camera and posts it to the Fediverse (Mastodon, Pleroma, etc.) Takes a photograph using the document camera and posts it to the Fediverse (Mastodon, Pleroma, etc.)
""" """
# TODO: maybe add @ocrbot mention or even better run OCR locally
# and use that as status and description
photo = self.send("PX", "photo")["photo"] photo = self.send("PX", "photo")["photo"]
media = self.masto.media_post(photo) media = self.masto.media_post(photo)
post = self.masto.status_post("", media_ids=[media]) post = self.masto.status_post("", in_reply_to_id=reply_to, media_ids=[media])
@add_command("mad", "Print Detailed Toot")
def showtoot(self, data):
"""
Prints out a detailed version of a fediverse post with all media. Allows
various social and public relations management.
"""
shortcode, _ = data.split(".")
toot_id = self.get_toot_id(shortcode)
t = self.masto.status(toot_id)
prn = self._get_small_printer()
prn.set(underline=1)
print("toot from:" + str(t.account))
username = str(t.account.display_name)
acct = str(t.account.acct)
prn.textln(username + " (" + acct + ")")
prn.set()
ttext = bleach.clean(t.content, tags=[], strip=True)
ttext = html.unescape(ttext)
prn.block_text(ttext, font="0")
prn.ln()
for media in t.media_attachments:
if media.type == "image":
req_data = requests.get(media.url)
im = PIL.Image.open(io.BytesIO(req_data.content))
if im.mode in ("L", "RGB", "P"):
im = PIL.ImageOps.equalize(im)
im.thumbnail((self.smprint["width"], 960), PIL.Image.ANTIALIAS)
prn.image(im, impl="bitImageColumn")
prn.textln("Boost")
prn.soft_barcode("code128", "PRmare." + shortcode, module_width=0.16)
prn.textln("Favorite")
prn.soft_barcode("code128", "PRmafv." + shortcode, module_width=0.16)
prn.textln("Reply")
prn.soft_barcode("code128", "PRmad." + shortcode, module_width=0.16)
prn.ln(2)
prn.cut()
prn.close()
@add_command("tootline", "Print Recent Toots") @add_command("tootline", "Print Recent Toots")
def tootline(self, data=None): def tootline(self, data=None):
@ -320,7 +374,8 @@ class PublicRelations(Bureau):
prn.set(underline=1) prn.set(underline=1)
print("toot from:" + str(t.account)) print("toot from:" + str(t.account))
username = str(t.account.display_name) username = str(t.account.display_name)
prn.textln(username) acct = str(t.account.acct)
prn.textln(username + " (" + acct + ")")
prn.set() prn.set()
ttext = bleach.clean(t.content, tags=[], strip=True) ttext = bleach.clean(t.content, tags=[], strip=True)
ttext = html.unescape(ttext) ttext = html.unescape(ttext)

Loading…
Cancel
Save