-
Notifications
You must be signed in to change notification settings - Fork 2
/
output_prn.py
32 lines (29 loc) · 928 Bytes
/
output_prn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright (C) 2012 Vivek Haldar
#
# Take in a dict containing fetched RSS data, and output to printable files in
# the current directory.
#
# Dict looks like:
# feed_title -> [list of articles]
# each article has (title, body).
#
# Author: Vivek Haldar <[email protected]>
import codecs
import escpos
from datetime import datetime
import textwrap
import output
class OutputPrn(output.Output):
def output(self):
articles = self._articles
for f in articles:
prn = escpos.Escpos('%s.prn' % f.replace('/', '_'))
for a in articles[f]:
title, body = a
# Cut body down to 100 words.
short_body = ' '.join(body.split()[:100])
prn.bigtext(f + '\n')
prn.bigtext(textwrap.fill(title, 32) + '\n')
prn.text(textwrap.fill(body, 32))
prn.text('\n\n\n')
prn.flush()