Skip to content

Commit de9e26c

Browse files
Add section support to OPML exporter.
This is not part of the standard but nextcloud uses the same method. I have added a proposal for explicit support in the OPML git.
1 parent 598573f commit de9e26c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/gpodder/opml.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ def create_outline(self, doc, channel):
141141
outline.setAttribute('type', self.FEED_TYPE)
142142
return outline
143143

144+
def create_section(self, doc, name):
145+
"""
146+
Creates an empty OPML ouline element used to divide sections.
147+
"""
148+
section = doc.createElement('outline')
149+
section.setAttribute('title', name)
150+
section.setAttribute('text', name)
151+
return section
152+
144153
def write(self, channels):
145154
"""
146155
Creates a XML document containing metadata for each
@@ -165,8 +174,16 @@ def write(self, channels):
165174
opml.appendChild(head)
166175

167176
body = doc.createElement('body')
177+
sections = {}
168178
for channel in channels:
169-
body.appendChild(self.create_outline(doc, channel))
179+
if channel.section not in sections.keys():
180+
sections[channel.section] = self.create_section(doc, channel.section)
181+
182+
sections[channel.section].appendChild(self.create_outline(doc, channel))
183+
184+
for section in sections.values():
185+
body.appendChild(section)
186+
170187
opml.appendChild(body)
171188

172189
if self.filename is None:

0 commit comments

Comments
 (0)