add proper notifications for masto. keep track of last read notification.

workspace
Brendan Howell 4 years ago
parent 35dfe8d067
commit 27d44a08b9

@ -73,6 +73,8 @@ class PublicRelations(Bureau):
# setup DBs to map short codes to tweet ids # setup DBs to map short codes to tweet ids
self.tweetdb = self.dbenv.open_db(b"tweetdb") self.tweetdb = self.dbenv.open_db(b"tweetdb")
with self.dbenv.begin(db=self.tweetdb) as txn:
self.last_mast_notif = txn.get(b"last_mast_notif")
def get_tweet_id(self, tweet_hash): def get_tweet_id(self, tweet_hash):
""" """
@ -341,17 +343,24 @@ class PublicRelations(Bureau):
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")
notifications = self.masto.notifications() 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.text("NOTIFICATIONS:\r\n")
prn.set(text_type="NORMAL") prn.set(text_type="NORMAL")
# store the last notification id
self.last_mast_notif = notifications[0].id
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: for note in notifications:
username = t.account.display_name.encode("cp437", "ignore") + \ username = note.account.display_name.encode("cp437", "ignore") + \
b" (" + t.account.acct.encode("cp437", "ignore") + b")" 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._raw(username)
prn.text(":\r\n" + str(note.keys()) + "\r\n") prn.text(":\r\n" + str(note.status) + "\r\n")
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.text("\r\n\r\n")
prn.cut() prn.cut()

Loading…
Cancel
Save