Last active
January 14, 2019 23:45
-
-
Save fpcorso/802a006d9f403f27587b5f1ad96c7364 to your computer and use it in GitHub Desktop.
WordCamp Sessions XML to CSV
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
# Converts an XML generated from exporting | |
# sessions on a WordCamp site to a CSV file | |
# Use CMD/Powershell/Terminal to enter: | |
# python wordcamp-sessions-xml-to-csv.py | |
import xml.etree.ElementTree as ET | |
import csv | |
# Get the filenames | |
file_name = input("What is the XML file to convert? ") | |
csv_name = input("What should we call the CSV file? ") | |
# Tries to open the file and parse it | |
try: | |
tree = ET.parse(file_name) | |
except FileNotFoundError: | |
print("File not found!") | |
quit() | |
# Prepares our CSV file | |
fh = open(csv_name, mode="w", newline='') | |
csv_writer = csv.writer(fh) | |
csv_writer.writerow(["Speaker", "Title", "Description"]) | |
# Gets our root element | |
root = tree.getroot() | |
# Moves each session into the CSV | |
for item in root.findall("channel/item"): | |
csv_writer.writerow([item[3].text, item[0].text, item[6].text]) | |
# Closes CSV file | |
fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment