04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

448 CHAPTER 23 ■ PROJECT 4: IN THE NEWS<br />

Figure 23-2. A news page with more than one source<br />

The full source code of the second implementation is found in Listing 23-2.<br />

Listing 23-2. A More Flexible News Gathering Agent (newsagent2.py)<br />

from __future__ import generators<br />

from nntplib import NNTP<br />

from time import strftime, time, localtime<br />

from email import message_from_string<br />

from urllib import urlopen<br />

import textwrap<br />

import re<br />

day = 24 * 60 * 60 # Number of seconds in one day<br />

def wrap(string, max=70):<br />

"""<br />

Wraps a string to a maximum line width.<br />

"""<br />

return '\n'.join(textwrap.wrap(string)) + '\n'<br />

class NewsAgent:<br />

"""<br />

An object that can distribute news items from news<br />

sources to news destinations.<br />

"""

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!