Created
January 26, 2014 23:53
-
-
Save hyonschu/8641090 to your computer and use it in GitHub Desktop.
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
chunk = '4\r\n 2000-2-18 cutomer: A3K605XFFC7NIA rating: 1 votes: 19 helpful: 12\r\n 2000-2-23 cutomer: A3E7NRYT2NPPD1 rating: 1 votes: 16 helpful: 13\r\n 2000-4-17 cutomer: A2V8O1IKTM6FXH rating: 4 votes: 7 helpful: 7\r\n 2000-4-27 cutomer: AJZ6R63Q8Y8XX rating: 4 votes: 9 helpful: 9\r\n 2000-5-16 cutomer: ALM383FHKU6DM rating: 5 votes: 8 helpful: 0\r\n 2000-7-19 cutomer: AH1YESR0CVI04 rating: 5 votes: 1 helpful: 1\r\n 2000-10-11 cutomer: A2JVHERZ91ZZ5Q rating: 4 votes: 7 helpful: 4\r\n 2000-12-4 cutomer: AQKZ1Q0UI740W rating: 5 votes: 17 helpful: 17\r\n 2001-8-26 cutomer: ASFY7TDEW608J rating: 5 votes: 13 helpful: 1\r\n 2002-7-1 cutomer: ANKFQMNL9E89N rating: 5 votes: 3 helpful: 3\r\n 2002-7-2 cutomer: A1OOI3Q34M6K8Q rating: 5 votes: 2 helpful: 2\r\n 2002-7-29 cutomer: A1Z4NWNR1XLM8U rating: 5 votes: 9 helpful: 9\r\n 2002-10-17 cutomer: A1K10NRS5J7IGO rating: 5 votes: 5 helpful: 5\r\n 2002-10-17 cutomer: A1K10NRS5J7IGO rating: 5 votes: 19 helpful: 19\r\n 2003-1-7 cutomer: A3D6UIK7Q7XIAB rating: 4 votes: 10 helpful: 10\r\n 2003-5-15 cutomer: A362Y9GGATXOOW rating: 5 votes: 8 helpful: 8\r\n 2003-11-23 cutomer: A3IK7AVY3TWW1R rating: 5 votes: 10 helpful: 10\r\n 2004-8-3 cutomer: A3F5K5KGDMA4Y5 rating: 2 votes: 4 helpful: 0' | |
def reviews(chunk): | |
clean = [] | |
reviewed = chunk.split("avg rating: ") | |
#print reviewed[1] | |
#reviewed = reviewed[1] | |
#print reviewed | |
reviewed = reviewed[1].split("\n") | |
reviewed.pop(0) | |
#print reviewed , "THESE ARE ALL TEH REVIEWS" | |
for term in reviewed: | |
#print term | |
term = term.replace("cutomer:", "--") | |
term = term.replace("rating:", "--") | |
term = term.replace("votes:", "--") | |
term = term.replace("helpful:", "--") | |
#term = term.replace("\n", "") | |
#print term | |
templist = term.split("--") | |
print "THESE ARE THE TERMS IN THE LIST:" | |
print templist | |
print templist[0].strip() | |
print templist[1].strip() | |
print templist[2].strip() | |
print templist[3].strip() | |
print templist[4].strip() | |
#d = dict(date=templist[0], cutomer=templist[1], rating=templist[2]) | |
#tdict = dict(date=templist[0].strip(), cutomer=templist[1].strip())#, rating=templist[2].strip(), votes=templist[3].strip(), helpful=templist[4].strip()) | |
#print d , "THOISHDSUEKHF JKEFJKEJF EWKJFK EW" | |
clean.append(dict(date=templist[0], cutomer=templist[1], rating=templist[2])) | |
return templist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment