refactor barcode generation for svgs.

workspace
Brendan Howell 5 years ago
parent b017dd9ded
commit d41cbe33e4

@ -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()

@ -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 = '<img class="endnotebc" src="%s"/>' % 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 = '<img src="%s"/>' % encoded_data

@ -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')
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")

Loading…
Cancel
Save