From b7498d12078cdabba51ed1675de42356ce13baae Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Fri, 4 Dec 2020 22:40:33 +0100 Subject: [PATCH] finish masto-fedi implementation --- .../bureau/publicrelations/publicrelations.py | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/screenless/bureau/publicrelations/publicrelations.py b/screenless/bureau/publicrelations/publicrelations.py index 22c679c..8810eb6 100644 --- a/screenless/bureau/publicrelations/publicrelations.py +++ b/screenless/bureau/publicrelations/publicrelations.py @@ -287,14 +287,68 @@ class PublicRelations(Bureau): toot_id = self.get_toot_id(shortcode) self.masto.status_favorite(toot_id) - @add_command("tootpic", "Post a Document Camera Image to the Fediverse") - def toot_pic(self): + @add_command("marp", "Reply to a toot") + 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.) """ + # TODO: maybe add @ocrbot mention or even better run OCR locally + # and use that as status and description photo = self.send("PX", "photo")["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") def tootline(self, data=None): @@ -320,7 +374,8 @@ class PublicRelations(Bureau): prn.set(underline=1) print("toot from:" + str(t.account)) username = str(t.account.display_name) - prn.textln(username) + acct = str(t.account.acct) + prn.textln(username + " (" + acct + ")") prn.set() ttext = bleach.clean(t.content, tags=[], strip=True) ttext = html.unescape(ttext)