Skip to content

Instantly share code, notes, and snippets.

@tom-monaco
Created July 12, 2015 11:55
Show Gist options
  • Save tom-monaco/244eb0ba16662ad56085 to your computer and use it in GitHub Desktop.
Save tom-monaco/244eb0ba16662ad56085 to your computer and use it in GitHub Desktop.
Reformats eBay's Feedbacks XML into a CSV format
#!/usr/local/bin/python
import sys
import xml.etree.ElementTree as ET
tree = ET.parse(sys.stdin)
root = tree.getroot()
ns = { 'ebay' : 'urn:ebay:apis:eBLBaseComponents'}
def get_tag_data(element, tag_name):
tag = element.find('ebay:' + tag_name, ns)
if tag == None:
return ''
else:
return tag.text
for feedback in root.findall(".//ebay:FeedbackDetail", ns):
user = get_tag_data(feedback, 'CommentingUser')
time = get_tag_data(feedback, 'CommentTime')
item_id = get_tag_data(feedback, 'ItemID')
transaction_id = get_tag_data(feedback, 'TransactionID')
text = get_tag_data(feedback, 'CommentText')
print user + ',' + time + "," + item_id + "," + transaction_id + ',' + '"' + text.encode('utf-8') + '"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment