diff --git a/examples/csv-to-opml.csv b/examples/csv-to-opml.csv new file mode 100644 index 0000000..1d2fa97 --- /dev/null +++ b/examples/csv-to-opml.csv @@ -0,0 +1,3 @@ +Text,Url +Example,https://example.org +Another Example,https://example.org/another diff --git a/examples/csv-to-opml.py b/examples/csv-to-opml.py new file mode 100644 index 0000000..72f5bbf --- /dev/null +++ b/examples/csv-to-opml.py @@ -0,0 +1,26 @@ +import csv + +from opyml import OPML, Outline + + +def main() -> None: + document = OPML() + + with open("examples/csv-to-opml.csv", "r") as example_csv: + csv_reader = csv.DictReader(example_csv) + + for row in csv_reader: + document.body.outlines.append( + Outline( + # Convert to str because text is a required OPML attribute + # and row.get() can return None. + text=str(row.get("Text")), + xml_url=row.get("Url"), + ) + ) + + print(document.to_xml()) + + +if __name__ == "__main__": + main()