diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 38db6fd..b407c32 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -229,6 +229,7 @@ class Bureau(object): """ fp = io.BytesIO() barcode.generate("CODE128", code, writer=barcode.writer.SVGWriter(), output=fp) + fp.seek(0) # TODO: add file output return fp.read().decode() diff --git a/screenless/bureau/publications/publications.py b/screenless/bureau/publications/publications.py index 5b1896c..f4157c9 100644 --- a/screenless/bureau/publications/publications.py +++ b/screenless/bureau/publications/publications.py @@ -165,7 +165,7 @@ class Publications(Bureau): continue # skip bogus links tmpcode = self._make_shorturl(link.attrib["href"]) - svg = barcode.get("CODE128", "PBr." + tmpcode).raw + svg = self.bc_svg("PBr." + tmpcode) footnote = html.makeelement("div") footnote.attrib["class"] = "footnote" @@ -173,7 +173,7 @@ class Publications(Bureau): notetext.text = str(notecount) + ". " + link.attrib["href"] footnote.append(notetext) #TODO: make this barcode inline thing a util method - encoded_svg = b64encode(svg).decode() + encoded_svg = b64encode(svg.encode()).decode() encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg svg = '' % encoded_data footnote.append(lxml.html.fromstring(svg)) @@ -276,8 +276,8 @@ class Publications(Bureau): entry.source = feed.feed.title entry.dbhash = self._make_shorturl(entry.link) - entry.svg = barcode.get("CODE128", "PBr." + entry.dbhash).raw - encoded_svg = b64encode(entry.svg).decode() + entry.svg = self.bc_svg("PBr." + entry.dbhash) + encoded_svg = b64encode(entry.svg.encode()).decode() encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg entry.svg = '' % encoded_data diff --git a/screenless/bureau/publicrelations/publicrelations.py b/screenless/bureau/publicrelations/publicrelations.py index 98b5836..dafaacd 100644 --- a/screenless/bureau/publicrelations/publicrelations.py +++ b/screenless/bureau/publicrelations/publicrelations.py @@ -51,16 +51,25 @@ class PublicRelations(Bureau): self.auth = twitter.OAuth(oauth_token, oauth_secret, CK, CS) self.t.t = twitter.Twitter(auth=self.auth) + # TODO: expand config to have other masto servers MASTO_CREDS = os.path.expanduser('~/.screenless/masto_creds') if not os.path.exists(MASTO_CREDS): Mastodon.create_app('screenless', api_base_url='https://mastodon.social', to_file=MASTO_CREDS) + # TODO: catch the error when our token is too old and throw it out self.masto = Mastodon(client_id=MASTO_CREDS, api_base_url='https://mastodon.social') - masto_user = self.config["mastodon"]["user"] - masto_pass = self.config["mastodon"]["password"] - self.masto.log_in(masto_user, masto_pass) + try: + masto_user = self.config["mastodon"]["user"] + masto_pass = self.config["mastodon"]["password"] + self.masto.log_in(masto_user, masto_pass) + except KeyError: + print("no mastodon config found.") + print("you can add a 'mastodon:' section to PR.yml with:") + print(" user: myuser") + print(" password: mypassword") + print("skipping masto login for now...") # setup DBs to map short codes to tweet ids self.tweetdb = self.dbenv.open_db(b"tweetdb")