Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion zulip/integrations/rss/rss-bot
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ from typing_extensions import override

import zulip

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from rss_feeds import parse_feed_file_lines

VERSION = "0.9"
RSS_DATA_DIR = os.path.expanduser(os.path.join("~", ".cache", "zulip-rss"))

Expand Down Expand Up @@ -214,7 +217,7 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:

try:
with open(opts.feed_file) as f:
feed_urls: List[str] = [feed.strip() for feed in f.readlines()]
feed_urls = parse_feed_file_lines(f.readlines())
except OSError:
log_error_and_exit(f"Unable to read feed file at {opts.feed_file}.")

Expand Down
2 changes: 2 additions & 0 deletions zulip/integrations/rss/rss_feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def parse_feed_file_lines(lines: list[str]) -> list[str]:
return [line.strip() for line in lines if line.strip()]
19 changes: 19 additions & 0 deletions zulip/integrations/rss/test_rss_feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
from unittest import TestCase

sys.path.insert(0, os.path.dirname(__file__))

from rss_feeds import parse_feed_file_lines


class TestRssFeedParsing(TestCase):
def test_skips_blank_lines(self) -> None:
lines = ["https://example.com/feed", "", " ", "https://other.test/rss"]
self.assertEqual(
parse_feed_file_lines(lines),
["https://example.com/feed", "https://other.test/rss"],
)

def test_strips_whitespace(self) -> None:
self.assertEqual(parse_feed_file_lines([" https://example.com/feed \n"]), ["https://example.com/feed"])
Loading