Created
July 12, 2015 11:55
-
-
Save tom-monaco/244eb0ba16662ad56085 to your computer and use it in GitHub Desktop.
Reformats eBay's Feedbacks XML into a CSV format
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
#!/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