gpodder/src/gpodder/liblocdbwriter.py

60 lines
1.7 KiB
Python
Raw Normal View History

#
# gPodder
# Copyright (c) 2005-2006 Thomas Perl <thp@perli.net>
# Released under the GNU General Public License (GPL)
#
#
# liblocdbwriter.py -- rss output writer for your downloaded feeds
# thomas perl <thp@perli.net> 20060109
#
#
import codecs
from datetime import datetime
class writeLocalDB( object):
ofile = None
def __init__( self, filename, channel):
self.ofile = codecs.open( filename, "w", 'iso-8859-1', 'replace')
self.ofile.write( '<?xml version="1.0" encoding="ISO-8859-1"?>'+"\n")
self.ofile.write( '<!-- local download database, generated by gPodder -->'+"\n")
self.ofile.write( '<rss version="2.0">'+"\n")
self.ofile.write( '<channel>'+"\n")
self.ofile.write( '<pubDate>' + datetime.now().ctime() + '</pubDate>'+"\n")
self.writeTitle( channel.title)
self.writeDescription( channel.description)
self.writeLink( channel.link)
for item in channel.items:
self.addItem( item)
self.close()
def writeTitle( self, title):
self.ofile.write( '<title>'+title+'</title>'+"\n")
def writeDescription( self, description):
self.ofile.write( '<description>'+description+'</description>'+"\n")
def writeLink( self, link):
self.ofile.write( '<link>'+link+'</link>'+"\n")
def close( self):
self.ofile.write( '</channel>'+"\n")
self.ofile.write( '</rss>'+"\n")
self.ofile.close()
def addItem( self, item):
self.ofile.write( '<item>'+"\n")
self.ofile.write( '<title>'+item.title+'</title>'+"\n")
self.ofile.write( '<description>'+item.description+'</description>'+"\n")
self.ofile.write( '<url>'+item.url+'</url>'+"\n")
self.ofile.write( '</item>'+"\n")