def json_to_csv(stories): lines = [] for story in stories: lines.append( (story['objectID'], datetime.strptime(story['created_at'], "%Y-%m-%dT%H:%M:%SZ"), story['url'], story['points'], story['title']) ) return build_csv(lines, header=['objectID', 'created_at', 'url', 'points', 'title'], file=io.StringIO())
def json_to_csv(stories): lines = list() #loads json into csv files for a consistent data format for story in stories: lines.append((story["objectID"], datetime.strptime(story["created_at"], "%Y-%m-%dT%H:%M:%SZ"), story["url"], story["points"], story["title"])) return build_csv( lines, header=["objectID", "created_at", "url", "points", "title"], file=io.StringIO())
def json_to_csv(stories): lines = [] for story in stories: objectID = story['objectID'] created_at = datetime.strptime(story['created_at'], "%Y-%m-%dT%H:%M:%SZ") url = story['url'] points = story['points'] title = story['title'] lines.append((objectID, created_at, url, points, title)) header = ['objectID', 'created_at', 'url', 'points', 'title'] return build_csv(lines, header, file=io.StringIO())