Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created April 30, 2020 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hamletbatista/f77d6cd6343b240f6451116a5a7c08b6 to your computer and use it in GitHub Desktop.
Save hamletbatista/f77d6cd6343b240f6451116a5a7c08b6 to your computer and use it in GitHub Desktop.
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