cleaned up layout and data for news

workspace
Brendan Howell 8 years ago
parent 2a5d40498e
commit a2d17c4190

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

@ -3,9 +3,11 @@ import email.mime.application
import email.mime.multipart
import email.mime.text
from email.header import decode_header, make_header
import imaplib
#import imaplib
import os.path
import random
import smtplib
import string
import code128
import imapclient
@ -87,9 +89,9 @@ class MailRoom(Bureau):
"""
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)
# format and tidy header data
@ -112,7 +114,9 @@ class MailRoom(Bureau):
# TODO: save interesting attachments to files
# should clean these up on delete
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(">", "&gt;")
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
needed)
"""
with self.dbenv.begin(db=self.postdb_rev) as txn:
shortcode = txn.get(msgid.encode())
msgid = str(msgid).encode()
with self.dbenv.begin(db=self.postdb_rev, write=True) as txn:
shortcode = txn.get(msgid)
if shortcode is not None:
return shortcode
else:
shortcode = ''.join(random.choice(string.ascii_letters +
string.digits) for _ in range(5))
txn.put(msgid.encode(), shortcode.encode())
with self.dbenv.begin(db=self.postdb) as txn:
txn.put(shortcode.encode(), msgid.encode())
return shortcode
string.digits) for _ in range(5)).encode()
print("saving msgid", msgid, shortcode)
txn.put(msgid, shortcode)
with self.dbenv.begin(db=self.postdb, write=True) as txn:
txn.put(shortcode, msgid)
return shortcode.decode()
@add_command("fax", "Send a Document Camera Image via Email")
def fax(self, data):
@ -293,15 +298,25 @@ class MailRoom(Bureau):
msgs = []
for msgid, data in resp.items():
msg = self._make_msg_object(msgid, data)
shortcode = self._imap2shortcode(msgid)
#msg = self._make_msg_object(msgid, data)
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
msg.d_bc = code128.svg("POd." + shortcode).encode()
msg.sp_bc = code128.svg("POsp." + shortcode).encode()
msg.r_bc = code128.svg("POr." + shortcode).encode()
msg.d_bc = code128.svg("POd." + shortcode)
msg.sp_bc = code128.svg("POsp." + shortcode)
msg.r_bc = code128.svg("POr." + shortcode)
msgs.append(msg)
msgs.append(msg.__dict__)
return msgs

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

@ -101,11 +101,11 @@ class Publications(Bureau):
news = self._get_news()
# TODO: get weather
# TODO: get finance
print("news", news[0])
inbox = self.send("PO", "unread")
date = datetime.today().strftime("%A %B %e, %Y")
if inbox is None:
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")
def print_url(self, data):

Loading…
Cancel
Save