[python] zope ano/ne
Petr Vanek
vanous na penguin.cz
Středa Červen 26 04:52:50 CEST 2002
ahoj,
nevim na kolik to sledujete, ale na rootu se objevila debata na tema
zope ano/ne. kazdy produkt ma sve priznivce a sve odpurce, ale protoze
jsme tady spise ve skupine priznivcu, mohl by nekdo vzit tu kritiku bod
po bodu a okomentovat, popripade vyvratit/potvrdit pravdivost, nejlepe
na zaklade vlasti zkusenosti. nerikam, ze to musi byt na rootu, klidne
to muze probehnout touto konferou, nebo to muzem hodit na py.cz jako
clanecek a pak to tam nalinkovat...
http://www.root.cz/clanek.phtml?id=1215
p.s. vim, ze takovych debat je tady kolem plno, pokud si myslite, ze to
zato nestoji, tak to nechte plavat...
p.p.s prikladam svuj prvni pythonovsky script ;-), muze se hodit ;-)
--
bye
Vanous
-------------------------------------------------
Petr Vanek ..... ./\. ....
Debian GNU Linux .. _|\| |/|_ ..
vanous na penguin.cz .. \ /...
http://www.penguin.cz/~vanous ... >______< ...
Angus, Ontario, CA ...... / .......
-------------------------------------------------
Registered linux user #217487
#usage: python urlrss2html.py /tmp/01.html
"""
This application uses pyexpat to convert RSS documents to HTML.
"""
import sys,codecs,os,urllib
from xml.parsers import expat
# --- Templates
top = \
"""
<a href=%s>%s</a>
"""
# --- The converter
class RSS2HTML:
def __init__(self, out = None):
self._out = out or sys.stdout
# tracking state
self._data = ""
self._first_item = 1
self._title = None
self._link = None
self._descr = None
def start_tag(self, name, attrs):
self._data = ""
if name == "item":
self._descr = None # reset for this item
if self._first_item:
self._out.write("\n<ul>\n")
self._first_item = 0
def end_tag(self, name):
if name == "title":
self._title = self._data
elif name == "link":
self._link = self._data
elif name == "description":
self._descr = self._data
elif name == "language":
self._out.write(top % (self._link, self._title))
if self._descr != None:
self._out.write("<p>%s</p>" % self._descr)
elif name == "item":
self._out.write(' <li><a href="%s">%s</a> %s\n' %
(self._link,self._title,self._descr or ""))
elif name == "rss":
self._out.write("</ul>\n")
def data_handler(self, data):
self._data = self._data + data
# --- The driver
def convert(sysid, out):
app = RSS2HTML(out)
p = expat.ParserCreate()
p.StartElementHandler = app.start_tag
p.EndElementHandler = app.end_tag
p.CharacterDataHandler = app.data_handler
error = 0
inf = sysid
buf = inf.read(16384)
while buf != "":
if p.Parse(buf, 0) != 1:
error = 1
break
buf = inf.read(16384)
inf.close()
if error or p.Parse("", 1) != 1:
print "ERROR: %s in %s:%s:%s" % (expat.ErrorString(p.ErrorCode),
sysid, p.ErrorLineNumber,
p.ErrorColumnNumber)
# --- The main program
servery=['http://penguin.cz/cgi-bin/toISO-8859-2.en/rss.php3','http://w
ww.root.cz/rss/'] out = codecs.open(sys.argv[1], "w", "iso-8859-2")
for i in servery:
sysid = urllib.urlopen(i)
convert(sysid,out)
print "formating...",i
#convert(sysid, out)
out.close()
os.system("dillo file:" + sys.argv[1] + "&")
------------- další část ---------------
A non-text attachment was scrubbed...
Name: [žádný popis není k dispozici]
Type: application/pgp-signature
Size: 189 bytes
Desc: [žádný popis není k dispozici]
URL: <http://www.py.cz/pipermail/python/attachments/20020625/51db304a/attachment.asc>
Další informace o konferenci Python