Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #New lines are fine
- #Must have leading and trailing triple-quotes
- text = '''Example Post by tgb | 0v (3c)
- Another by someone | -1v (0c)
- I "hate" the CSV, format by foo | -5v (0c)'''
- #change this filename to what you want to output to!
- output = file("output.csv", "w")
- lines = text.split("\n")
- for l in lines:
- start, end = tuple(l.split(" | "))
- title = start[:start.rfind(" by")]
- title = title.replace("\"", "'") #Replace quotes with single quotes
- author = start[start.rfind("by")+3:]
- votes = int(end[:end.find("v")])
- comments = int(end[end.find("(")+1:end.find("c")])
- line_out = "\"%s\", \"%s\", %s, %s\n"%(title, author, votes, comments)
- output.write(line_out)
- output.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement