Add a CSV to OPML example.
This commit is contained in:
parent
cc8bd20a54
commit
a9f357cf0c
|
@ -0,0 +1,3 @@
|
||||||
|
Text,Url
|
||||||
|
Example,https://example.org
|
||||||
|
Another Example,https://example.org/another
|
|
|
@ -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()
|
Loading…
Reference in New Issue