adam_tetz
05/03/2023, 9:27 AMREQUEST:
GET <https://uri.example.com/resource?from_ts=1682380800&to_ts=1682985600>
RESPONSE:
{
"from_date": 1682380800000,
"to_date": 1682985600000,
"key": "value"
}
The timeframe is limited for let’s say a week. What would be a good Meltano way to replicate data over a longer timeframe? I’m thinking of using the to_date as a replication key and use a paginator to keep track of the next calls. Does anyone know a good example on this? Any help is appreciated :)josue_sehnem
05/03/2023, 12:37 PMadam_tetz
05/03/2023, 1:07 PMjosue_sehnem
05/03/2023, 1:12 PMuser
05/03/2023, 5:49 PM@dataclasses.dataclass
class Range(t.Generic[T]):
"""A range of values."""
lower: T | None
upper: T
class NumberRangePaginator(BaseAPIPaginator[Range[float]]):
"""Paginator that works with number ranges."""
def __init__(
self,
start: float,
end: float,
step: float,
*args: t.Any,
**kwargs: t.Any,
) -> None:
"""Create a new paginator."""
start_value = Range(None, start)
super().__init__(start_value, *args, **kwargs)
self._end = end
if step <= 0:
msg = "Step must be a positive number."
raise ValueError(msg)
self._step = step
def get_next(self, response: Response) -> Range[float] | None:
"""Get the next page value.
Args:
response: API response object.
Returns:
The next page value.
"""
next_value = self._value.upper + self._step
if next_value >= self._end:
return None
return Range(self._value.upper, next_value)
adam_tetz
05/03/2023, 9:24 PMadam_tetz
05/05/2023, 3:57 PM