def main(directory, debug): basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) stdout.buffer.write( generate_feed(channel_dict, find_files(channel_dict["url"], Path(directory))))
def test_feed_with_some_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") files = find_files("http://example.com", Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, files) tree = etree.fromstring(feed) items = tree.findall("channel")[0].findall("item") expected_titles = ["Some silence", "More silence", "Even more silence"] assert expected_titles == [i.findall("title")[0].text for i in items]
def test_feed_with_some_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") files = find_files("http://example.com", Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, files) tree = etree.fromstring(feed) items = tree.findall("channel")[0].findall("item") expected_titles = ['Some silence', 'More silence', 'Even more silence'] assert expected_titles == [i.findall("title")[0].text for i in items]
def test_feed_with_no_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, []) tree = etree.fromstring(feed) channel = tree.findall("channel")[0] assert channel.findall("title")[0].text == channel_dict["title"] assert channel.findall( "description")[0].text == channel_dict["description"] assert channel.findall("link")[0].text == channel_dict["url"]
def main(directory, debug): basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) stdout.buffer.write( generate_feed( channel_dict, find_files(channel_dict["url"], Path(directory))) )
def test_feed_with_no_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, []) tree = etree.fromstring(feed) channel = tree.findall("channel")[0] assert channel.findall("title")[0].text == channel_dict["title"] assert ( channel.findall("description")[0].text == channel_dict["description"] ) assert channel.findall("link")[0].text == channel_dict["url"]
def main(directory: str, debug: bool, output_file: str) -> None: basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) if not channel_dict["base_url"].endswith("/"): getLogger(__name__).error("base_url should end with a /") exit(1) feed = generate_feed( channel_dict, output_file, find_files(channel_dict["base_url"], Path(directory)) ) with open(output_file, "wb") as output_f: output_f.write(feed)