1
0
mirror of synced 2026-02-02 16:02:07 -05:00
Files
airbyte/airbyte-cdk/python/airbyte_cdk/sources/declarative/extractors/jello.py
Alexandre Girard 57dd7a9d4b [low-code connectors] use jello instead of jq (#13570)
* use jello instead of jq

* reset

* rename

* remove print
2022-06-07 14:10:26 -07:00

31 lines
1.1 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from typing import List
import requests
from airbyte_cdk.sources.declarative.decoders.decoder import Decoder
from airbyte_cdk.sources.declarative.extractors.http_extractor import HttpExtractor
from airbyte_cdk.sources.declarative.interpolation.jinja import JinjaInterpolation
from airbyte_cdk.sources.declarative.types import Record
from jello import lib as jello_lib
class JelloExtractor(HttpExtractor):
default_transform = "."
def __init__(self, transform: str, decoder: Decoder, config, kwargs=None):
if kwargs is None:
kwargs = dict()
self._interpolator = JinjaInterpolation()
self._transform = transform
self._config = config
self._kwargs = kwargs
self._decoder = decoder
def extract_records(self, response: requests.Response) -> List[Record]:
response_body = self._decoder.decode(response)
script = self._interpolator.eval(self._transform, self._config, default=self.default_transform, **{"kwargs": self._kwargs})
return jello_lib.pyquery(response_body, script)