Last active
March 12, 2018 17:13
-
-
Save rfmcnally/d41c1deff438a9c01dbf0ae2d5d300b1 to your computer and use it in GitHub Desktop.
Sample Python class for processing NDJSON object from Import.io API
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 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