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