From f854e5e12a25b2b85b07f373194cf0ebf9744ba6 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Thu, 2 Jan 2020 13:31:47 +0100 Subject: [PATCH] fixes for news svgs. tidy up news layout. --- screenless/bureau/bureau.py | 8 ++++++-- screenless/bureau/mailroom/mailroom.py | 18 ++++++++++-------- screenless/bureau/publications/news.html | 4 ++-- screenless/bureau/publications/publications.py | 5 +++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 0b7f882..8d8caf0 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -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() diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py index feda675..ea35a33 100644 --- a/screenless/bureau/mailroom/mailroom.py +++ b/screenless/bureau/mailroom/mailroom.py @@ -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__) diff --git a/screenless/bureau/publications/news.html b/screenless/bureau/publications/news.html index 82ec0f7..13ff30c 100644 --- a/screenless/bureau/publications/news.html +++ b/screenless/bureau/publications/news.html @@ -132,11 +132,11 @@

Yesterday's Tomorrows

- +
% for entry in news: diff --git a/screenless/bureau/publications/publications.py b/screenless/bureau/publications/publications.py index f4157c9..ed42e67 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 = 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 = '' % encoded_data