rsstube/scripts/opml.py

33 lines
794 B
Python
Raw Normal View History

#!/usr/bin/python3
# class for representing and writing an OPML outline for RSS feeds
class Opml:
def __init__(self, title=""):
self.title = title
self.feeds = []
@staticmethod
def get_date():
from datetime import datetime
return datetime.now().strftime("%a %b %d %H:%M:%S %Y")
def add_feed(self, feed, title="", html_url=""):
line = '<outline text="' + title + '" type="rss" htmlUrl="' + html_url + '" xmlUrl="' + feed + '"/>'
self.feeds.append(line)
def get_opml(self):
opml = '''<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>''' + self.title + '''</title>
<dateModified>''' + self.get_date() + '''</dateModified>
</head>
<body>'''
for line in self.feeds:
opml += "\n\t\t" + line
opml += '''
</body>
</opml>'''
return opml