2006-02-04 14:21:07 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2006-03-19 15:21:48 +01:00
|
|
|
import codecs
|
|
|
|
|
2006-02-04 14:21:07 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
class writeLocalDB( object):
|
|
|
|
ofile = None
|
|
|
|
|
|
|
|
def __init__( self, filename, channel):
|
2006-03-19 18:44:47 +01:00
|
|
|
self.ofile = codecs.open( filename, "w", 'iso-8859-1', 'replace')
|
2006-02-04 14:21:07 +01:00
|
|
|
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")
|
|
|
|
|
|
|
|
|