fixes for news svgs. tidy up news layout.

workspace
Brendan Howell 5 years ago
parent 355a705be0
commit f854e5e12a

@ -233,14 +233,18 @@ class Bureau(object):
db = KeyValStore(self.dbenv, name)
return db
def bc_svg(self, code, tofile=False, outfile=None):
def bc_svg(self, code, tofile=False, outfile=None, width=0.2, height=15.0,
notext=False):
"""
generate a CODE128 barcode as an SVG
returns a string or can write to a tmp file or specific
file given arguments
"""
fp = io.BytesIO()
barcode.generate("CODE128", code, writer=barcode.writer.SVGWriter(), output=fp)
# TODO: support notext option
writer = barcode.writer.SVGWriter(module_width=width,
module_height=height)
barcode.generate("CODE128", code, writer=writer, output=fp)
fp.seek(0)
# TODO: add file output
return fp.read().decode()

@ -9,7 +9,6 @@ import random
import smtplib
import string
import barcode
import imapclient
from bureau import Bureau, add_command, add_api
@ -58,10 +57,13 @@ class MailRoom(Bureau):
self.imapserv.select_folder("INBOX")
else:
print("you need to configure an IMAP account!")
print("add a [user] section to PO.ini with:")
print(" login = mylogin")
print(" password = mypassword")
print(" host = my.imap.server.address.com")
print("add a user: section to PO.yml with:")
print(" login: mylogin")
print(" password: mypassword")
print(" host: my.imap.server.address.com")
print(" spamfolder: Junk")
print(" trashfolder: Trash")
print(" ssl: True")
# setup db's for mapping short codes to IMAP msg ids (and reversed)
self.postdb = self.dbenv.open_db(b"postdb")
@ -313,9 +315,9 @@ class MailRoom(Bureau):
msg.subject = clean_header(envelope.subject.decode("utf-8"))
# make action barcodes
msg.d_bc = str(barcode.get("code128", "POd." + shortcode).raw)
msg.sp_bc = str(barcode.get("code128", "POsp." + shortcode).raw)
msg.r_bc = str(barcode.get("code128", "POr." + shortcode).raw)
msg.d_bc = self.bc_svg("POd." + shortcode)
msg.sp_bc = self.bc_svg("POsp." + shortcode)
msg.r_bc = self.bc_svg("POr." + shortcode)
msgs.append(msg.__dict__)

@ -132,11 +132,11 @@
</head>
<body>
<h1 id="masthead">Yesterday's Tomorrows</h1>
<!--div id="edition">
<div id="edition">
<div id="motto">Semper Contemporarius</div>
<div id="date">${date}</div>
<div class="clearfloats"></div>
</div-->
</div>
<div id="columnspacer"> </div>
<div id="columns">
% for entry in news:

@ -165,7 +165,7 @@ class Publications(Bureau):
continue # skip bogus links
tmpcode = self._make_shorturl(link.attrib["href"])
svg = self.bc_svg("PBr." + tmpcode)
svg = self.bc_svg("PBr." + tmpcode, height=7.0)
footnote = html.makeelement("div")
footnote.attrib["class"] = "footnote"
@ -276,7 +276,8 @@ class Publications(Bureau):
entry.source = feed.feed.title
entry.dbhash = self._make_shorturl(entry.link)
entry.svg = self.bc_svg("PBr." + entry.dbhash)
entry.svg = self.bc_svg("PBr." + entry.dbhash, width=0.24,
height=7.0)
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

Loading…
Cancel
Save