[Jsign-commits] CVS: pyweb news.py,1.1,1.2
Brought to you by:
borillo
|
From: Ricardo B. D. <bo...@us...> - 2001-08-31 14:06:28
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv16902
Modified Files:
news.py
Log Message:
He añadido una mejora en las clases de infraestructura y ademas he añadido
un primer test de envio de mensajes por maili ... (a mejorar :)
Index: news.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/news.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** news.py 2001/08/28 07:58:05 1.1
--- news.py 2001/08/31 07:10:58 1.2
***************
*** 1,5 ****
--- 1,7 ----
from xml.sax import *
import urllib, sys
+ from smtplib import SMTP
+ # Clases definidas en el documento RDF =====================================================
class RDFElement:
def __init__(self):
***************
*** 7,18 ****
--- 9,34 ----
self.link = ""
+ def __str__(self):
+ return '<a href="' + self.link + '">' + self.title + '</a>'
+
class Channel(RDFElement):
def __init__(self):
self.desc = ""
+ def __str__(self):
+ out = '<h1>Bienvenido al canal <a href="' + self.link + '">' + self.title + '</a><br>'
+ out = out + self.desc + '<br>'
+ return out
+
class Image(RDFElement):
def __init__(self):
self.url = ""
+ def __str__(self):
+ out = '<a href="' + self.link + '">' + self.title + '</a>'
+ out = out + '<img src="' + self.url + '">'
+ return out
+
+ # Clase que se encarga de parsear el documento de noticias y de extraer el texto ===========
class NewsParser(ContentHandler):
def __init__(self):
***************
*** 21,24 ****
--- 37,41 ----
self.news = []
self.actual = None
+ self.output = ""
def startElement(self, name, attributes):
***************
*** 51,72 ****
def endDocument(self):
! sys.stdout.write('<html>' + '\n')
! sys.stdout.write(' <body>' + '\n')
for item in self.news:
! if isinstance(item, Channel):
! sys.stdout.write(' <h1>Bienvenido al canal <a href="' + item.link + '">' + item.title + '</a><br>' + '\n')
! sys.stdout.write(' ' + item.desc + '<br>\n');
! elif isinstance(item, Image):
! sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
! sys.stdout.write(' <img src="' + item.url + '">' + '\n')
! else:
! sys.stdout.write(' Nuevo articulo<br>' + '\n')
! sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
! sys.stdout.write(' </body>' + '\n')
! sys.stdout.write('</html>' + '\n')
if __name__ == "__main__":
! url = 'http://slashdot.org/slashdot.rdf'
! parse(urllib.urlopen(url), NewsParser())
--- 68,89 ----
def endDocument(self):
! self.output = '<html>\n'
! self.output = self.output + '<body>\n'
for item in self.news:
! self.output = self.output + ' ' + str(item) + '\n'
! self.output = self.output + ' </body>\n'
! self.output = self.output + '</html>\n'
!
! def getOutput(self):
! return self.output
if __name__ == "__main__":
! url = 'http://barrapunto.com/barrapunto.rdf'
! np = NewsParser()
! parse(urllib.urlopen(url), np)
!
! a = SMTP('mail.uji.es')
! sys.stdout.write(np.getOutput())
! a.sendmail('bo...@si...','bo...@si...', np.getOutput())
|