예제 #1
0
파일: main.py 프로젝트: Aleks-me/Projects
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())
예제 #2
0
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())
예제 #3
0
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())