|
|
|
@ -150,23 +150,18 @@ class PublicRelations(Bureau):
|
|
|
|
|
|
|
|
|
|
prn = self._get_small_printer()
|
|
|
|
|
# TODO: abstract this to use a simple templating system instead of raw
|
|
|
|
|
prn.codepage = "cp437"
|
|
|
|
|
|
|
|
|
|
# TODO: add fancier formatting i.e. inverted text for username/handle
|
|
|
|
|
tweets = self.t.t.statuses.home_timeline(count=count,
|
|
|
|
|
tweet_mode="extended")
|
|
|
|
|
out = ""
|
|
|
|
|
for t in tweets:
|
|
|
|
|
prn.set(text_type="U")
|
|
|
|
|
username = t["user"]["name"].encode("cp437", "ignore")
|
|
|
|
|
prn._raw(username)
|
|
|
|
|
prn.text("\r\n")
|
|
|
|
|
username = t["user"]["name"]
|
|
|
|
|
prn.textln(username)
|
|
|
|
|
prn.set(text_type="NORMAL")
|
|
|
|
|
twtext = html.unescape(t["full_text"])
|
|
|
|
|
t_wrapped = textwrap.fill(twtext, width=self.smprint["textwidth"])\
|
|
|
|
|
+ "\r\n"
|
|
|
|
|
t_enc = t_wrapped.encode("cp437", "ignore")
|
|
|
|
|
prn._raw(t_enc)
|
|
|
|
|
prn.block_text(twtext)
|
|
|
|
|
prn.ln()
|
|
|
|
|
|
|
|
|
|
if "media" in t["entities"]:
|
|
|
|
|
if len(t["entities"]["media"]) > 0:
|
|
|
|
@ -182,10 +177,12 @@ class PublicRelations(Bureau):
|
|
|
|
|
prn.image(im, impl="bitImageColumn")
|
|
|
|
|
|
|
|
|
|
tw_shortcode = self.short_tweet_id(t["id_str"])
|
|
|
|
|
prn.barcode("PRtwd." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.text("\r\n\r\n")
|
|
|
|
|
#prn.barcode("PRtwd." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.soft_barcode("CODE128", "PRtwd." + tw_shortcode)
|
|
|
|
|
prn.ln(2)
|
|
|
|
|
|
|
|
|
|
prn.cut()
|
|
|
|
|
prn.close()
|
|
|
|
|
|
|
|
|
|
@add_command("twd", "Print Tweet Details")
|
|
|
|
|
def tw_details(self, data):
|
|
|
|
@ -196,18 +193,13 @@ class PublicRelations(Bureau):
|
|
|
|
|
tweet_id = self.get_tweet_id(shortcode)
|
|
|
|
|
tweet = self.t.t.statuses.show(id=tweet_id, tweet_mode="extended")
|
|
|
|
|
prn = self._get_small_printer()
|
|
|
|
|
prn.codepage = "cp437"
|
|
|
|
|
|
|
|
|
|
prn.set(text_type="U")
|
|
|
|
|
username = tweet["user"]["name"].encode("cp437", "ignore")
|
|
|
|
|
prn._raw(username)
|
|
|
|
|
prn.text("\r\n")
|
|
|
|
|
username = tweet["user"]["name"]
|
|
|
|
|
prn.textln(username)
|
|
|
|
|
prn.set(text_type="NORMAL")
|
|
|
|
|
twtext = html.unescape(tweet["full_text"])
|
|
|
|
|
t_wrapped = textwrap.fill(twtext, width=self.smprint["textwidth"])\
|
|
|
|
|
+ "\r\n"
|
|
|
|
|
t_enc = t_wrapped.encode("cp437", "ignore")
|
|
|
|
|
prn._raw(t_enc)
|
|
|
|
|
prn.(twtext)
|
|
|
|
|
|
|
|
|
|
if "media" in tweet["entities"]:
|
|
|
|
|
for entity in tweet["entities"]["media"]:
|
|
|
|
@ -224,14 +216,17 @@ class PublicRelations(Bureau):
|
|
|
|
|
|
|
|
|
|
tw_shortcode = self.short_tweet_id(tweet["id_str"])
|
|
|
|
|
prn.text("retweet\r\n")
|
|
|
|
|
prn.barcode("PRtwrt." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
#prn.barcode("PRtwrt." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.soft_barcode("CODE128", "PRtwrt." + tw_shortcode)
|
|
|
|
|
prn.text("like\r\n")
|
|
|
|
|
prn.barcode("PRtwlk." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
#prn.barcode("PRtwlk." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.soft_barcode("CODE128", "PRtwlk." + tw_shortcode)
|
|
|
|
|
prn.text("\r\n\r\n")
|
|
|
|
|
prn.barcode("PRtwre." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.text("\r\n\r\n")
|
|
|
|
|
|
|
|
|
|
#prn.barcode("PRtwre." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.soft_barcode("CODE128", "PRtwre." + tw_shortcode)
|
|
|
|
|
prn.ln(2)
|
|
|
|
|
prn.cut()
|
|
|
|
|
prn.close()
|
|
|
|
|
|
|
|
|
|
@add_command("twrt", "Re-Tweet")
|
|
|
|
|
def tw_retweet(self, data):
|
|
|
|
@ -288,7 +283,6 @@ class PublicRelations(Bureau):
|
|
|
|
|
photo = self.send("PX", "photo")["photo"]
|
|
|
|
|
media = self.masto.media_post(photo)
|
|
|
|
|
post = self.masto.status_post("", media_ids=[media])
|
|
|
|
|
#self.log.debug(str(post))
|
|
|
|
|
|
|
|
|
|
@add_command("tootline", "Print Recent Toots")
|
|
|
|
|
def tootline(self, data=None):
|
|
|
|
@ -313,16 +307,12 @@ class PublicRelations(Bureau):
|
|
|
|
|
out = ""
|
|
|
|
|
for t in toots:
|
|
|
|
|
prn.set(text_type="U")
|
|
|
|
|
username = t.account.display_name.encode("cp437", "ignore")
|
|
|
|
|
prn._raw(username)
|
|
|
|
|
prn.text("\r\n")
|
|
|
|
|
username = t.account.display_name
|
|
|
|
|
prn.textln(username)
|
|
|
|
|
prn.set(text_type="NORMAL")
|
|
|
|
|
ttext = bleach.clean(t.content, tags=[], strip=True)
|
|
|
|
|
ttext = html.unescape(ttext)
|
|
|
|
|
t_wrapped = textwrap.fill(ttext, width=self.smprint["textwidth"])\
|
|
|
|
|
+ "\r\n"
|
|
|
|
|
t_enc = t_wrapped.encode("cp437", "ignore")
|
|
|
|
|
prn._raw(t_enc)
|
|
|
|
|
prn.block_text(ttext)
|
|
|
|
|
|
|
|
|
|
if len(t.media_attachments) > 0:
|
|
|
|
|
img = None
|
|
|
|
@ -342,12 +332,13 @@ class PublicRelations(Bureau):
|
|
|
|
|
prn.image(im, impl="bitImageColumn")
|
|
|
|
|
|
|
|
|
|
tw_shortcode = self.short_tweet_id(str(t["id"]))
|
|
|
|
|
prn.barcode("PRmad." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
#prn.barcode("PRmad." + tw_shortcode, "CODE128", function_type="B")
|
|
|
|
|
prn.soft_barcode("CODE128", "PRmad." + tw_shortcode)
|
|
|
|
|
|
|
|
|
|
notifications = self.masto.notifications(since_id=self.last_mast_notif)
|
|
|
|
|
if len(notifications) > 0:
|
|
|
|
|
prn.set(text_type="B")
|
|
|
|
|
prn.text("NOTIFICATIONS:\r\n")
|
|
|
|
|
prn.textln("NOTIFICATIONS:")
|
|
|
|
|
prn.set(text_type="NORMAL")
|
|
|
|
|
|
|
|
|
|
# store the last notification id
|
|
|
|
@ -355,16 +346,16 @@ class PublicRelations(Bureau):
|
|
|
|
|
with self.dbenv.begin(db=self.tweetdb, write=True) as txn:
|
|
|
|
|
txn.put(b"last_mast_notif", self.last_mast_notif.encode())
|
|
|
|
|
for note in notifications:
|
|
|
|
|
username = note.account.display_name.encode("cp437", "ignore") + \
|
|
|
|
|
b" (" + note.account.acct.encode("cp437", "ignore") + b")"
|
|
|
|
|
username = note.account.display_name + " (" + note.account.acct + ")"
|
|
|
|
|
prn.text(note["type"] + " " + str(note["created_at"]) + " from ")
|
|
|
|
|
prn._raw(username)
|
|
|
|
|
prn.text(":\r\n" + str(note["status"]) + "\r\n")
|
|
|
|
|
prn.textln(username + ":")
|
|
|
|
|
prn.textln(str(note["status"]))
|
|
|
|
|
with self.dbenv.begin(db=self.tweetdb, write=True) as txn:
|
|
|
|
|
txn.put(shortcode.encode(), tweet_id.encode())
|
|
|
|
|
|
|
|
|
|
prn.text("\r\n\r\n")
|
|
|
|
|
prn.ln(2)
|
|
|
|
|
prn.cut()
|
|
|
|
|
prn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|