cleaned up layout and data for news

workspace
Brendan Howell 7 years ago
parent 2a5d40498e
commit a2d17c4190

@ -340,23 +340,22 @@ class Bureau(object):
self.log.debug("got method: " + ref) self.log.debug("got method: " + ref)
if (ref in self.commands) or (ref in self.api): if (ref in self.commands) or (ref in self.api):
# catch TypeErrors for case of bogus params # TODO: cope with data for calls with no params
try: if ref in self.api:
if ref in self.api: if data:
if data: data = json.loads(data)
data = json.loads(data) ret = json.dumps(self.api[ref](data))
ret = json.dumps(self.api[ref](data))
else:
ret = json.dumps(self.api[ref]())
else: else:
if data: ret = json.dumps(self.api[ref]())
ret = self.commands[ref](data) else:
else: if data:
ret = self.commands[ref]() ret = self.commands[ref](data)
if ret is None: else:
ret = "" ret = self.commands[ref]()
ret = "0" + ret if ret is None:
self._recv.send_string(ret) ret = ""
ret = "0" + ret
self._recv.send_string(ret)
else: else:
self.log.warning("error! Command/API %s not found", ref) self.log.warning("error! Command/API %s not found", ref)
self._recv.send_unicode("Error! Command/API not found.") self._recv.send_unicode("Error! Command/API not found.")

@ -3,9 +3,11 @@ import email.mime.application
import email.mime.multipart import email.mime.multipart
import email.mime.text import email.mime.text
from email.header import decode_header, make_header from email.header import decode_header, make_header
import imaplib #import imaplib
import os.path import os.path
import random
import smtplib import smtplib
import string
import code128 import code128
import imapclient import imapclient
@ -87,9 +89,9 @@ class MailRoom(Bureau):
""" """
util tidies up message headers deals with encoding util tidies up message headers deals with encoding
""" """
internaldate = resp_obj[imap_id][b'INTERNALDATE'] internaldate = resp_obj[b'INTERNALDATE']
msg_data = resp_obj[imap_id][b'RFC822'].decode('utf-8') msg_data = resp_obj[b'RFC822'].decode('utf-8')
msg_obj = email.message_from_string(msg_data) msg_obj = email.message_from_string(msg_data)
# format and tidy header data # format and tidy header data
@ -112,7 +114,9 @@ class MailRoom(Bureau):
# TODO: save interesting attachments to files # TODO: save interesting attachments to files
# should clean these up on delete # should clean these up on delete
if part.get_content_type() == "text/plain": if part.get_content_type() == "text/plain":
msg.content = part.get_payload(decode=True).decode("utf-8") msg.content = part.get_payload(decode=True)
print("msg content:", msg.content)
msg.content = msg.content.decode("utf-8")
msg.content = msg.content.replace("<", "&lt;") msg.content = msg.content.replace("<", "&lt;")
msg.content = msg.content.replace(">", "&gt;") msg.content = msg.content.replace(">", "&gt;")
msg.content = msg.content.replace("\n", "<br />") msg.content = msg.content.replace("\n", "<br />")
@ -132,18 +136,19 @@ class MailRoom(Bureau):
returns a short code for a given IMAP id (creating a new mapping if returns a short code for a given IMAP id (creating a new mapping if
needed) needed)
""" """
with self.dbenv.begin(db=self.postdb_rev) as txn: msgid = str(msgid).encode()
shortcode = txn.get(msgid.encode()) with self.dbenv.begin(db=self.postdb_rev, write=True) as txn:
shortcode = txn.get(msgid)
if shortcode is not None: if shortcode is not None:
return shortcode return shortcode
else: else:
shortcode = ''.join(random.choice(string.ascii_letters + shortcode = ''.join(random.choice(string.ascii_letters +
string.digits) for _ in range(5)) string.digits) for _ in range(5)).encode()
txn.put(msgid.encode(), shortcode.encode()) print("saving msgid", msgid, shortcode)
with self.dbenv.begin(db=self.postdb) as txn: txn.put(msgid, shortcode)
txn.put(shortcode.encode(), msgid.encode()) with self.dbenv.begin(db=self.postdb, write=True) as txn:
return shortcode txn.put(shortcode, msgid)
return shortcode.decode()
@add_command("fax", "Send a Document Camera Image via Email") @add_command("fax", "Send a Document Camera Image via Email")
def fax(self, data): def fax(self, data):
@ -293,15 +298,25 @@ class MailRoom(Bureau):
msgs = [] msgs = []
for msgid, data in resp.items(): for msgid, data in resp.items():
msg = self._make_msg_object(msgid, data) #msg = self._make_msg_object(msgid, data)
shortcode = self._imap2shortcode(msgid) msg = Message()
shortcode = self._imap2shortcode(msgid).decode("utf-8")
envelope = data[b"ENVELOPE"]
msg.msgid = str(msgid)
sender = envelope.from_[0]
msg.fromaddr = sender.mailbox + b"@" + sender.host
msg.fromaddr = clean_header(msg.fromaddr.decode("utf-8"))
msg.fromname = clean_header(sender.name.decode("utf-8"))
msg.date = data[b"INTERNALDATE"].strftime("%d. %B %Y %I:%M%p")
msg.subject = clean_header(envelope.subject.decode("utf-8"))
# make action barcodes # make action barcodes
msg.d_bc = code128.svg("POd." + shortcode).encode() msg.d_bc = code128.svg("POd." + shortcode)
msg.sp_bc = code128.svg("POsp." + shortcode).encode() msg.sp_bc = code128.svg("POsp." + shortcode)
msg.r_bc = code128.svg("POr." + shortcode).encode() msg.r_bc = code128.svg("POr." + shortcode)
msgs.append(msg) msgs.append(msg.__dict__)
return msgs return msgs

@ -3,9 +3,17 @@
<title>NEWS</title> <title>NEWS</title>
<meta charset="utf-8"> <meta charset="utf-8">
<style type="text/css"> <style type="text/css">
@media print {
@page {
size: A4;
}
}
html {
font-size: 120%;
}
body { body {
font-family: "CMU Serif"; font-family: "CMU Serif";
font-size: 13pt; font-size: 24pt;
line-height: 1; line-height: 1;
} }
h1 { h1 {
@ -22,12 +30,13 @@
column-count: 4; column-count: 4;
text-align: justify; text-align: justify;
clear: both; clear: both;
margin-top: 1em;
} }
#masthead { #masthead {
font-family: "Fold"; font-family: "Fold";
font-weight: 400; font-weight: 400;
text-transform: uppercase; text-transform: uppercase;
font-size: 12vw; font-size: 50mm;
text-align: center; text-align: center;
margin: 0; margin: 0;
} }
@ -37,6 +46,7 @@
padding: 5px; padding: 5px;
clear: both; clear: both;
font-variant: small-caps; font-variant: small-caps;
font-size: 24pt;
} }
#motto { #motto {
float: left; float: left;
@ -65,10 +75,12 @@
} }
.entry .barcode{ .entry .barcode{
text-align: left; text-align: left;
margin-top: 0.25em;
} }
.entry .barcode svg { .entry .barcode svg {
width: 100%; width: 130%;
height: 7mm; margin-left: -15%;
border: 1px solid black;
} }
.entry .summary{ .entry .summary{
text-align: justify; text-align: justify;
@ -79,7 +91,7 @@
<h1 id="masthead">Yesterday's Tomorrows</h1> <h1 id="masthead">Yesterday's Tomorrows</h1>
<div id="edition"> <div id="edition">
<div id="motto">Semper Contemporarius</div> <div id="motto">Semper Contemporarius</div>
<div id="date"> DATE_HERE</div> <div id="date">${date}</div>
<div class="clearfloats"></div> <div class="clearfloats"></div>
</div> </div>
<div id="columns"> <div id="columns">
@ -101,11 +113,11 @@
% for msg in inbox: % for msg in inbox:
<tr> <tr>
<td>${msg.fromstr}</td> <td>${msg["fromname"]} ${msg["fromaddr"]}</td>
<td>${msg.subject}</td><td>${msg.date}</td> <td>${msg["subject"]}</td><td>${msg["date"]}</td>
</tr> </tr>
<tr><td> </td><td>READ</td><td>DELETE</td><td>MARK AS SPAM</td></tr> <tr><td> </td><td>READ</td><td>DELETE</td><td>MARK AS SPAM</td></tr>
<tr><td> </td><td>${msg.r_bc}</td><td>${msg.d_bc}</td><td>${msg.sp_bc}</td></tr> <tr><td> </td><td>${msg["r_bc"]}</td><td>${msg["d_bc"]}</td><td>${msg["sp_bc"]}</td></tr>
% endfor % endfor
</table> </table>
</div> </div>

@ -101,11 +101,11 @@ class Publications(Bureau):
news = self._get_news() news = self._get_news()
# TODO: get weather # TODO: get weather
# TODO: get finance # TODO: get finance
print("news", news[0])
inbox = self.send("PO", "unread") inbox = self.send("PO", "unread")
date = datetime.today().strftime("%A %B %e, %Y")
if inbox is None: if inbox is None:
inbox = [] # if IMAP times out just move on... inbox = [] # if IMAP times out just move on...
self.print_full("news.html", news=news, inbox=inbox) self.print_full("news.html", news=news, inbox=inbox, date=date)
@add_command("r", "Print a web page for reading") @add_command("r", "Print a web page for reading")
def print_url(self, data): def print_url(self, data):

Loading…
Cancel
Save