Skip to content

Instantly share code, notes, and snippets.

@rfmcnally
Last active March 12, 2018 17:13
Show Gist options
  • Save rfmcnally/d41c1deff438a9c01dbf0ae2d5d300b1 to your computer and use it in GitHub Desktop.
Save rfmcnally/d41c1deff438a9c01dbf0ae2d5d300b1 to your computer and use it in GitHub Desktop.
Sample Python class for processing NDJSON object from Import.io API
import os
import json
import requests
class Extractor(object):
""" An Import.io Extractor """
def __init__(self, guid):
self.guid = guid
def latest_json(self):
""" Returns the JSON from the latest run """
url = "https://data.import.io/extractor/{0}/json/latest".format(self.guid)
querystring = {"_apikey": os.environ['IMPORT_IO_API_KEY']}
headers = {"Accept": "application/x-ldjson"}
response = requests.get(url, params=querystring, headers=headers, stream=True)
list_resp = response.text.splitlines()
json_resp = list(map(lambda x: json.loads(x), list_resp))
return json_resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment