Created
April 30, 2020 01:17
-
-
Save hamletbatista/f77d6cd6343b240f6451116a5a7c08b6 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
import json | |
from jsonpath_ng import jsonpath, parse | |
def get_content_formats(filename): | |
content_formats = dict() | |
image = parse("$..image") | |
video = parse("$..embedUrl") | |
local_business = parse("$..address") | |
review = parse("$..review") | |
top_story = parse("$..publisher") | |
faq = parse("$..acceptedAnswer") | |
job = parse("$..employmentType") | |
with open(filename,"r") as f: | |
data = json.load(f) | |
content_formats["image"] = [match.value for match in image.find(data)] | |
content_formats["video"] = [match.value for match in video.find(data)] | |
content_formats["local_business"] = [match.value for match in local_business.find(data)] | |
content_formats["review"] = [match.value for match in review.find(data)] | |
content_formats["top_story"] = [match.value for match in top_story.find(data)] | |
content_formats["faq"] = [match.value for match in faq.find(data)] | |
content_formats["job"] = [match.value for match in job.find(data)] | |
return content_formats | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment