Skip to content

Instantly share code, notes, and snippets.

@fpcorso
Last active January 14, 2019 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpcorso/802a006d9f403f27587b5f1ad96c7364 to your computer and use it in GitHub Desktop.
Save fpcorso/802a006d9f403f27587b5f1ad96c7364 to your computer and use it in GitHub Desktop.
WordCamp Sessions XML to CSV
# 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