-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ff-175 Export feeds to OPML file (#305)
- Loading branch information
Showing
8 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
- ff-174 — Custom API entry points for OpenAI and Gemini clients. | ||
- ff-175 — Export feeds to OPML file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from ffun.parsers import feed | ||
from ffun.parsers import feed, opml | ||
from ffun.parsers.entities import FeedInfo | ||
from ffun.parsers.feedly import extract_feeds | ||
|
||
|
||
def parse_opml(data: str) -> list[FeedInfo]: | ||
return extract_feeds(data) | ||
return opml.extract_feeds(data) | ||
|
||
|
||
create_opml = opml.create_opml | ||
|
||
|
||
parse_feed = feed.parse_feed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from ffun.core.tests.helpers import assert_compare_xml | ||
from ffun.domain.urls import url_to_uid | ||
from ffun.feeds.entities import Feed | ||
from ffun.parsers.entities import FeedInfo | ||
from ffun.parsers.opml import create_opml, extract_feeds | ||
|
||
|
||
class TestCreateOpml: | ||
|
||
def test(self, saved_feed: Feed, another_saved_feed: Feed) -> None: | ||
|
||
feeds = [saved_feed, another_saved_feed] | ||
feeds.sort(key=lambda feed: feed.title if feed.title is not None else "") | ||
|
||
content = create_opml(feeds) | ||
|
||
expected_content = f'<opml version="2.0"><head><title>Your subscriptions in feeds.fun</title></head><body><outline title="uncategorized" text="uncategorized"><outline title="{feeds[0].title}" text="{feeds[0].title}" type="rss" xmlUrl="{feeds[0].url}" /><outline title="{feeds[1].title}" text="{feeds[1].title}" type="rss" xmlUrl="{feeds[1].url}" /></outline></body></opml>' # noqa: E501 | ||
|
||
assert_compare_xml(content, expected_content.strip()) | ||
|
||
|
||
class TestExtractFeeds: | ||
|
||
def test(self, saved_feed: Feed, another_saved_feed: Feed) -> None: | ||
feeds = [saved_feed, another_saved_feed] | ||
feeds.sort(key=lambda feed: feed.title if feed.title is not None else "") | ||
|
||
content = create_opml(feeds) | ||
|
||
infos = extract_feeds(content) | ||
|
||
infos.sort(key=lambda info: info.title) | ||
|
||
assert infos[0] == FeedInfo( | ||
url=feeds[0].url, | ||
title=feeds[0].title if feeds[0].title is not None else "", | ||
description="", | ||
entries=[], | ||
uid=url_to_uid(feeds[0].url), | ||
) | ||
|
||
assert infos[1] == FeedInfo( | ||
url=feeds[1].url, | ||
title=feeds[1].title if feeds[1].title is not None else "", | ||
description="", | ||
entries=[], | ||
uid=url_to_uid(feeds[1].url), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters