diff --git a/screenless/bureau/publications/publications.py b/screenless/bureau/publications/publications.py index 590c09d..508aaca 100644 --- a/screenless/bureau/publications/publications.py +++ b/screenless/bureau/publications/publications.py @@ -56,8 +56,14 @@ class Publications(Bureau): res = txn.get(tmpcode.encode()) txn.put(tmpcode.encode(), url.encode()) + # chop wierdly long urls to be 500 chars (LMDB limit for keys) + # TODO: make sure we're not truncating some multi-byte unicode + if len(url.encode()) > 500: + url_key = url.encode()[0:500] + else: + url_key = url.encode() with self.dbenv.begin(write=True, db=self.rev_urldb) as txn: - txn.put(url.encode(), tmpcode.encode()) + txn.put(url_key, tmpcode.encode()) return tmpcode @@ -257,6 +263,7 @@ class Publications(Bureau): continue # ignore the old news we've already seen + # with self.dbenv.begin(db=self.rev_urldb) as txn: res = txn.get(entry.link.encode()) if res is not None: diff --git a/screenless/bureau/publicrelations/publicrelations.py b/screenless/bureau/publicrelations/publicrelations.py index 47eb5d2..75e3501 100644 --- a/screenless/bureau/publicrelations/publicrelations.py +++ b/screenless/bureau/publicrelations/publicrelations.py @@ -21,7 +21,7 @@ class PublicRelations(Bureau): """ The Public relations department manages the flow of information between the screenless office and the general public. It provides interfaces - for Twitter, Facebook and other electronic PR platforms. + for Twitter, Facebook, Mastodon and other electronic PR platforms. """ name = "Public Relations" @@ -93,22 +93,9 @@ class PublicRelations(Bureau): access_token = 'EAADixisn70ABADh2rEMZAYA8nGzd6ah8RFZA3URba263aCQ63ajLeTiZC5sgZCyIVSmRZBWReVsO9IuaLibX5RjW9Ja2tTZAbxgrDr1dPJzyGwcGTSV9bW1W4NigN0d9dFIH35W2fZBOkhvuLqOCDCBacIPjXPMxF7DRGyrz5lVHxTc04OlBeRX' page_id = "screenless" graph = facebook.GraphAPI(access_token) - #graph.put_object(parent_object=page_id, connection_name='feed', - # message='testing screenless post') print("uploading photo " + photo) graph.put_photo(image=open(photo, 'rb'), album_path=page_id + "/photos", message='#screenless') - #files = {"file": ("cam.jpg", open(photo, 'rb'))} - #args = {} - #args["access_token"] = access_token - #args["caption"] = "test cam" - #resp = requests.post(facebook.FACEBOOK_GRAPH_URL + graph.version + "/"\ - # + "me" + "/photos", - # files=files, - # params=args, - # timeout=graph.timeout, - # proxies=graph.proxies) - #print(resp.json()) @add_command("twtimeline", "Print Recent Tweets") def tw_timeline(self, data=None): @@ -164,11 +151,42 @@ class PublicRelations(Bureau): """ Print detailed tweet info and commands for reply, like, retweet, etc. """ + self.log.debug("got data " + str(data)) tweet_id = self.get_tweet_id(data) + self.log.debug("tweet details for id:" + tweet_id) tweet = self.t.t.statuses.show(id=tweet_id) + prn = printer.Usb(0x416, 0x5011, in_ep=0x81, out_ep=0x03) + prn.codepage = "cp437" - # TODO: print tweet details - pass + prn.set(text_type="U") + username = tweet["user"]["name"].encode("cp437", "ignore") + prn._raw(username) + prn.text("\r\n") + prn.set(text_type="NORMAL") + twtext = html.unescape(tweet["text"]) + t_wrapped = textwrap.fill(twtext, width=48) + "\r\n" + t_enc = t_wrapped.encode("cp437", "ignore") + prn._raw(t_enc) + + if "media" in tweet["entities"]: + if len(tweet["entities"]["media"]) > 0: + i_url = tweet["entities"]["media"][0]["media_url"] + filename = i_url.rsplit('/',1)[1] + filename = "/tmp/" + filename + print("fetching", i_url, filename) + urllib.request.urlretrieve(i_url, filename) + im = PIL.Image.open(filename) + if im.mode in ("L", "RGB", "P"): + im = PIL.ImageOps.equalize(im) + im.thumbnail((576, 576), PIL.Image.ANTIALIAS) + prn.image(im, impl="bitImageColumn") + + tw_shortcode = self.short_tweet_id(tweet["id_str"]) + prn.barcode("PRtwrt." + tw_shortcode, "CODE128", function_type="B") + prn.barcode("PRtwlk." + tw_shortcode, "CODE128", function_type="B") + prn.text("\r\n\r\n") + + prn.cut() @add_command("twrt", "Re-Tweet") def tw_retweet(self, data):