def collect_answer()

in python/mhtml_to_json.py [0:0]


def collect_answer(node):
    answer = {}
    # text
    text_node = find_itemprop(node, "text")
    if text_node is not None:
        text_node = text_cleanup(text_node)
        answer["text_markup"] = turn_into_string(text_node)

    # suggested|accepted
    suggested_accepted = node.get("itemprop")
    answer["status"] = suggested_accepted

    # date/time {created|modified|published}
    date_created = find_itemprop(node, "dateCreated")
    if date_created is not None:
        date_created = date_created.get("datetime")
        answer["date_created"] = date_created
    date_modified = find_itemprop(node, "dateModified")
    if date_modified is not None:
        date_modified = date_modified.get("datetime")
        answer["date_modified"] = date_modified
    date_published = find_itemprop(node, "datePublished")
    if date_published is not None:
        date_published = date_published.get("datetime")
        answer["date_published"] = date_published

    # upvote count
    upvote_count = find_itemprop(node, "upvoteCount")
    if upvote_count is not None:
        if upvote_count.tag == "meta":
            upvote_count = upvote_count.get("content")
        else:
            upvote_count = upvote_count.text
        answer["upvote_count"] = upvote_count

    # downvote count
    downvote_count = find_itemprop(node, "downvoteCount")
    if downvote_count is not None:
        if downvote_count.tag == "meta":
            downvote_count = downvote_count.get("content")
        else:
            downvote_count = downvote_count.text
        answer["downvote_count"] = downvote_count

    # comment count
    comment_count = find_itemprop(node, "commentCount")
    if comment_count is not None:
        if comment_count.tag == "meta":
            comment_count = comment_count.get("content")
        else:
            comment_count = comment_count.text
        answer["comment_count"] = comment_count

    return answer