ingestr 0.14.93__py3-none-any.whl → 0.14.98__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ingestr might be problematic. Click here for more details.
- ingestr/src/buildinfo.py +1 -1
- ingestr/src/couchbase_source/__init__.py +118 -0
- ingestr/src/couchbase_source/helpers.py +135 -0
- ingestr/src/cursor/__init__.py +83 -0
- ingestr/src/cursor/helpers.py +188 -0
- ingestr/src/factory.py +8 -0
- ingestr/src/hostaway/__init__.py +302 -0
- ingestr/src/hostaway/client.py +288 -0
- ingestr/src/revenuecat/__init__.py +16 -41
- ingestr/src/revenuecat/helpers.py +19 -73
- ingestr/src/socrata_source/__init__.py +83 -0
- ingestr/src/socrata_source/helpers.py +85 -0
- ingestr/src/socrata_source/settings.py +8 -0
- ingestr/src/sources.py +395 -0
- {ingestr-0.14.93.dist-info → ingestr-0.14.98.dist-info}/METADATA +2 -1
- {ingestr-0.14.93.dist-info → ingestr-0.14.98.dist-info}/RECORD +19 -10
- {ingestr-0.14.93.dist-info → ingestr-0.14.98.dist-info}/WHEEL +0 -0
- {ingestr-0.14.93.dist-info → ingestr-0.14.98.dist-info}/entry_points.txt +0 -0
- {ingestr-0.14.93.dist-info → ingestr-0.14.98.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
from typing import Iterable
|
|
2
|
+
|
|
3
|
+
import dlt
|
|
4
|
+
import pendulum
|
|
5
|
+
from dlt.common.typing import TDataItem
|
|
6
|
+
from dlt.sources import DltResource
|
|
7
|
+
|
|
8
|
+
from .client import HostawayClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dlt.source(max_table_nesting=0)
|
|
12
|
+
def hostaway_source(
|
|
13
|
+
api_key: str,
|
|
14
|
+
start_date: pendulum.DateTime,
|
|
15
|
+
end_date: pendulum.DateTime | None = None,
|
|
16
|
+
) -> Iterable[DltResource]:
|
|
17
|
+
"""
|
|
18
|
+
Hostaway API source for fetching listings and fee settings data.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
api_key: Hostaway API key for Bearer token authentication
|
|
22
|
+
start_date: Start date for incremental loading
|
|
23
|
+
end_date: End date for incremental loading (defaults to current time)
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Iterable[DltResource]: DLT resources for listings and/or fee settings
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
client = HostawayClient(api_key)
|
|
30
|
+
|
|
31
|
+
@dlt.resource(
|
|
32
|
+
write_disposition="merge",
|
|
33
|
+
name="listings",
|
|
34
|
+
primary_key="id",
|
|
35
|
+
)
|
|
36
|
+
def listings(
|
|
37
|
+
datetime=dlt.sources.incremental(
|
|
38
|
+
"latestActivityOn",
|
|
39
|
+
initial_value=start_date,
|
|
40
|
+
end_value=end_date,
|
|
41
|
+
range_end="closed",
|
|
42
|
+
range_start="closed",
|
|
43
|
+
),
|
|
44
|
+
) -> Iterable[TDataItem]:
|
|
45
|
+
"""
|
|
46
|
+
Fetch listings from Hostaway API with incremental loading.
|
|
47
|
+
Uses latestActivityOn field as the incremental cursor.
|
|
48
|
+
"""
|
|
49
|
+
start_dt = datetime.last_value
|
|
50
|
+
end_dt = (
|
|
51
|
+
datetime.end_value
|
|
52
|
+
if datetime.end_value is not None
|
|
53
|
+
else pendulum.now(tz="UTC")
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
yield from client.fetch_listings(start_dt, end_dt)
|
|
57
|
+
|
|
58
|
+
@dlt.resource(
|
|
59
|
+
write_disposition="merge",
|
|
60
|
+
name="listing_fee_settings",
|
|
61
|
+
primary_key="id",
|
|
62
|
+
)
|
|
63
|
+
def listing_fee_settings(
|
|
64
|
+
datetime=dlt.sources.incremental(
|
|
65
|
+
"updatedOn",
|
|
66
|
+
initial_value=start_date,
|
|
67
|
+
end_value=end_date,
|
|
68
|
+
range_end="closed",
|
|
69
|
+
range_start="closed",
|
|
70
|
+
),
|
|
71
|
+
) -> Iterable[TDataItem]:
|
|
72
|
+
"""
|
|
73
|
+
Fetch listing fee settings from Hostaway API with incremental loading.
|
|
74
|
+
Uses updatedOn field as the incremental cursor.
|
|
75
|
+
"""
|
|
76
|
+
start_dt = datetime.last_value
|
|
77
|
+
end_dt = (
|
|
78
|
+
datetime.end_value
|
|
79
|
+
if datetime.end_value is not None
|
|
80
|
+
else pendulum.now(tz="UTC")
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
yield from client.fetch_all_listing_fee_settings(start_dt, end_dt)
|
|
84
|
+
|
|
85
|
+
@dlt.resource(
|
|
86
|
+
write_disposition="replace",
|
|
87
|
+
name="listing_agreements",
|
|
88
|
+
)
|
|
89
|
+
def listing_agreements() -> Iterable[TDataItem]:
|
|
90
|
+
"""
|
|
91
|
+
Fetch listing agreements from Hostaway API.
|
|
92
|
+
|
|
93
|
+
Note: Uses replace mode, so no incremental loading.
|
|
94
|
+
"""
|
|
95
|
+
very_old_date = pendulum.datetime(1970, 1, 1, tz="UTC")
|
|
96
|
+
now = pendulum.now(tz="UTC")
|
|
97
|
+
yield from client.fetch_all_listing_agreements(very_old_date, now)
|
|
98
|
+
|
|
99
|
+
@dlt.resource(
|
|
100
|
+
write_disposition="replace",
|
|
101
|
+
name="listing_pricing_settings",
|
|
102
|
+
)
|
|
103
|
+
def listing_pricing_settings() -> Iterable[TDataItem]:
|
|
104
|
+
"""
|
|
105
|
+
Fetch listing pricing settings from Hostaway API.
|
|
106
|
+
|
|
107
|
+
Note: Uses replace mode, so no incremental loading.
|
|
108
|
+
"""
|
|
109
|
+
very_old_date = pendulum.datetime(1970, 1, 1, tz="UTC")
|
|
110
|
+
now = pendulum.now(tz="UTC")
|
|
111
|
+
yield from client.fetch_all_listing_pricing_settings(very_old_date, now)
|
|
112
|
+
|
|
113
|
+
@dlt.resource(
|
|
114
|
+
write_disposition="replace",
|
|
115
|
+
name="cancellation_policies",
|
|
116
|
+
)
|
|
117
|
+
def cancellation_policies() -> Iterable[TDataItem]:
|
|
118
|
+
yield from client.fetch_cancellation_policies()
|
|
119
|
+
|
|
120
|
+
@dlt.resource(
|
|
121
|
+
write_disposition="replace",
|
|
122
|
+
name="cancellation_policies_airbnb",
|
|
123
|
+
)
|
|
124
|
+
def cancellation_policies_airbnb() -> Iterable[TDataItem]:
|
|
125
|
+
yield from client.fetch_cancellation_policies_airbnb()
|
|
126
|
+
|
|
127
|
+
@dlt.resource(
|
|
128
|
+
write_disposition="replace",
|
|
129
|
+
name="cancellation_policies_marriott",
|
|
130
|
+
)
|
|
131
|
+
def cancellation_policies_marriott() -> Iterable[TDataItem]:
|
|
132
|
+
yield from client.fetch_cancellation_policies_marriott()
|
|
133
|
+
|
|
134
|
+
@dlt.resource(
|
|
135
|
+
write_disposition="replace",
|
|
136
|
+
name="cancellation_policies_vrbo",
|
|
137
|
+
)
|
|
138
|
+
def cancellation_policies_vrbo() -> Iterable[TDataItem]:
|
|
139
|
+
yield from client.fetch_cancellation_policies_vrbo()
|
|
140
|
+
|
|
141
|
+
@dlt.resource(
|
|
142
|
+
write_disposition="replace",
|
|
143
|
+
name="reservations",
|
|
144
|
+
selected=False,
|
|
145
|
+
)
|
|
146
|
+
def reservations() -> Iterable[TDataItem]:
|
|
147
|
+
yield from client.fetch_reservations()
|
|
148
|
+
|
|
149
|
+
@dlt.transformer(
|
|
150
|
+
data_from=reservations,
|
|
151
|
+
write_disposition="replace",
|
|
152
|
+
name="finance_fields",
|
|
153
|
+
)
|
|
154
|
+
def finance_fields(reservation_item: TDataItem) -> Iterable[TDataItem]:
|
|
155
|
+
@dlt.defer
|
|
156
|
+
def _get_finance_field(res_id):
|
|
157
|
+
return list(client.fetch_finance_field(res_id))
|
|
158
|
+
|
|
159
|
+
reservation_id_val = reservation_item.get("id")
|
|
160
|
+
if reservation_id_val:
|
|
161
|
+
yield _get_finance_field(reservation_id_val)
|
|
162
|
+
|
|
163
|
+
@dlt.resource(
|
|
164
|
+
write_disposition="replace",
|
|
165
|
+
name="reservation_payment_methods",
|
|
166
|
+
)
|
|
167
|
+
def reservation_payment_methods() -> Iterable[TDataItem]:
|
|
168
|
+
yield from client.fetch_reservation_payment_methods()
|
|
169
|
+
|
|
170
|
+
@dlt.transformer(
|
|
171
|
+
data_from=reservations,
|
|
172
|
+
write_disposition="replace",
|
|
173
|
+
name="reservation_rental_agreements",
|
|
174
|
+
)
|
|
175
|
+
def reservation_rental_agreements(
|
|
176
|
+
reservation_item: TDataItem,
|
|
177
|
+
) -> Iterable[TDataItem]:
|
|
178
|
+
@dlt.defer
|
|
179
|
+
def _get_rental_agreement(res_id):
|
|
180
|
+
return list(client.fetch_reservation_rental_agreement(res_id))
|
|
181
|
+
|
|
182
|
+
reservation_id = reservation_item.get("id")
|
|
183
|
+
if reservation_id:
|
|
184
|
+
yield _get_rental_agreement(reservation_id)
|
|
185
|
+
|
|
186
|
+
@dlt.transformer(
|
|
187
|
+
data_from=listings,
|
|
188
|
+
write_disposition="replace",
|
|
189
|
+
name="listing_calendars",
|
|
190
|
+
)
|
|
191
|
+
def listing_calendars(listing_item: TDataItem) -> Iterable[TDataItem]:
|
|
192
|
+
@dlt.defer
|
|
193
|
+
def _get_calendar(lst_id):
|
|
194
|
+
return list(client.fetch_listing_calendar(lst_id))
|
|
195
|
+
|
|
196
|
+
listing_id_val = listing_item.get("id")
|
|
197
|
+
if listing_id_val:
|
|
198
|
+
yield _get_calendar(listing_id_val)
|
|
199
|
+
|
|
200
|
+
@dlt.resource(
|
|
201
|
+
write_disposition="replace",
|
|
202
|
+
name="conversations",
|
|
203
|
+
)
|
|
204
|
+
def conversations() -> Iterable[TDataItem]:
|
|
205
|
+
yield from client.fetch_conversations()
|
|
206
|
+
|
|
207
|
+
@dlt.resource(
|
|
208
|
+
write_disposition="replace",
|
|
209
|
+
name="message_templates",
|
|
210
|
+
)
|
|
211
|
+
def message_templates() -> Iterable[TDataItem]:
|
|
212
|
+
yield from client.fetch_message_templates()
|
|
213
|
+
|
|
214
|
+
@dlt.resource(
|
|
215
|
+
write_disposition="replace",
|
|
216
|
+
name="bed_types",
|
|
217
|
+
)
|
|
218
|
+
def bed_types() -> Iterable[TDataItem]:
|
|
219
|
+
yield from client.fetch_bed_types()
|
|
220
|
+
|
|
221
|
+
@dlt.resource(
|
|
222
|
+
write_disposition="replace",
|
|
223
|
+
name="property_types",
|
|
224
|
+
)
|
|
225
|
+
def property_types() -> Iterable[TDataItem]:
|
|
226
|
+
yield from client.fetch_property_types()
|
|
227
|
+
|
|
228
|
+
@dlt.resource(
|
|
229
|
+
write_disposition="replace",
|
|
230
|
+
name="countries",
|
|
231
|
+
)
|
|
232
|
+
def countries() -> Iterable[TDataItem]:
|
|
233
|
+
yield from client.fetch_countries()
|
|
234
|
+
|
|
235
|
+
@dlt.resource(
|
|
236
|
+
write_disposition="replace",
|
|
237
|
+
name="account_tax_settings",
|
|
238
|
+
)
|
|
239
|
+
def account_tax_settings() -> Iterable[TDataItem]:
|
|
240
|
+
yield from client.fetch_account_tax_settings()
|
|
241
|
+
|
|
242
|
+
@dlt.resource(
|
|
243
|
+
write_disposition="replace",
|
|
244
|
+
name="user_groups",
|
|
245
|
+
)
|
|
246
|
+
def user_groups() -> Iterable[TDataItem]:
|
|
247
|
+
yield from client.fetch_user_groups()
|
|
248
|
+
|
|
249
|
+
@dlt.resource(
|
|
250
|
+
write_disposition="replace",
|
|
251
|
+
name="guest_payment_charges",
|
|
252
|
+
)
|
|
253
|
+
def guest_payment_charges() -> Iterable[TDataItem]:
|
|
254
|
+
yield from client.fetch_guest_payment_charges()
|
|
255
|
+
|
|
256
|
+
@dlt.resource(
|
|
257
|
+
write_disposition="replace",
|
|
258
|
+
name="coupons",
|
|
259
|
+
)
|
|
260
|
+
def coupons() -> Iterable[TDataItem]:
|
|
261
|
+
yield from client.fetch_coupons()
|
|
262
|
+
|
|
263
|
+
@dlt.resource(
|
|
264
|
+
write_disposition="replace",
|
|
265
|
+
name="webhook_reservations",
|
|
266
|
+
)
|
|
267
|
+
def webhook_reservations() -> Iterable[TDataItem]:
|
|
268
|
+
yield from client.fetch_webhook_reservations()
|
|
269
|
+
|
|
270
|
+
@dlt.resource(
|
|
271
|
+
write_disposition="replace",
|
|
272
|
+
name="tasks",
|
|
273
|
+
)
|
|
274
|
+
def tasks() -> Iterable[TDataItem]:
|
|
275
|
+
yield from client.fetch_tasks()
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
listings,
|
|
279
|
+
listing_fee_settings,
|
|
280
|
+
listing_agreements,
|
|
281
|
+
listing_pricing_settings,
|
|
282
|
+
cancellation_policies,
|
|
283
|
+
cancellation_policies_airbnb,
|
|
284
|
+
cancellation_policies_marriott,
|
|
285
|
+
cancellation_policies_vrbo,
|
|
286
|
+
reservations,
|
|
287
|
+
finance_fields,
|
|
288
|
+
reservation_payment_methods,
|
|
289
|
+
reservation_rental_agreements,
|
|
290
|
+
listing_calendars,
|
|
291
|
+
conversations,
|
|
292
|
+
message_templates,
|
|
293
|
+
bed_types,
|
|
294
|
+
property_types,
|
|
295
|
+
countries,
|
|
296
|
+
account_tax_settings,
|
|
297
|
+
user_groups,
|
|
298
|
+
guest_payment_charges,
|
|
299
|
+
coupons,
|
|
300
|
+
webhook_reservations,
|
|
301
|
+
tasks,
|
|
302
|
+
)
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
from typing import Callable, Iterable, Optional
|
|
2
|
+
|
|
3
|
+
import pendulum
|
|
4
|
+
from dlt.sources.helpers.requests import Client
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HostawayClient:
|
|
8
|
+
BASE_URL = "https://api.hostaway.com"
|
|
9
|
+
|
|
10
|
+
def __init__(self, api_key: str) -> None:
|
|
11
|
+
self.session = Client(raise_for_status=False).session
|
|
12
|
+
self.session.headers.update({"Authorization": f"Bearer {api_key}"})
|
|
13
|
+
|
|
14
|
+
def _fetch_single(self, url: str, params: Optional[dict] = None) -> Iterable[dict]:
|
|
15
|
+
response = self.session.get(url, params=params, timeout=30)
|
|
16
|
+
response.raise_for_status()
|
|
17
|
+
response_data = response.json()
|
|
18
|
+
|
|
19
|
+
if isinstance(response_data, dict) and "result" in response_data:
|
|
20
|
+
items = response_data["result"]
|
|
21
|
+
elif isinstance(response_data, list):
|
|
22
|
+
items = response_data
|
|
23
|
+
else:
|
|
24
|
+
items = []
|
|
25
|
+
|
|
26
|
+
if isinstance(items, list):
|
|
27
|
+
for item in items:
|
|
28
|
+
yield item
|
|
29
|
+
elif isinstance(items, dict):
|
|
30
|
+
yield items
|
|
31
|
+
|
|
32
|
+
def _paginate(
|
|
33
|
+
self,
|
|
34
|
+
url: str,
|
|
35
|
+
params: Optional[dict] = None,
|
|
36
|
+
limit: int = 100,
|
|
37
|
+
process_item: Optional[Callable[[dict], dict]] = None,
|
|
38
|
+
) -> Iterable[dict]:
|
|
39
|
+
offset = 0
|
|
40
|
+
if params is None:
|
|
41
|
+
params = {}
|
|
42
|
+
|
|
43
|
+
while True:
|
|
44
|
+
page_params = {**params, "limit": limit, "offset": offset}
|
|
45
|
+
response = self.session.get(url, params=page_params, timeout=30)
|
|
46
|
+
response.raise_for_status()
|
|
47
|
+
response_data = response.json()
|
|
48
|
+
|
|
49
|
+
if isinstance(response_data, dict) and "result" in response_data:
|
|
50
|
+
items = response_data["result"]
|
|
51
|
+
elif isinstance(response_data, list):
|
|
52
|
+
items = response_data
|
|
53
|
+
else:
|
|
54
|
+
items = []
|
|
55
|
+
|
|
56
|
+
if not items or (isinstance(items, list) and len(items) == 0):
|
|
57
|
+
break
|
|
58
|
+
|
|
59
|
+
if isinstance(items, list):
|
|
60
|
+
for item in items:
|
|
61
|
+
if process_item:
|
|
62
|
+
item = process_item(item)
|
|
63
|
+
yield item
|
|
64
|
+
elif isinstance(items, dict):
|
|
65
|
+
if process_item:
|
|
66
|
+
items = process_item(items)
|
|
67
|
+
yield items
|
|
68
|
+
|
|
69
|
+
if isinstance(items, list) and len(items) < limit:
|
|
70
|
+
break
|
|
71
|
+
elif isinstance(items, dict):
|
|
72
|
+
break
|
|
73
|
+
|
|
74
|
+
offset += limit
|
|
75
|
+
|
|
76
|
+
def fetch_listings(
|
|
77
|
+
self,
|
|
78
|
+
start_time: pendulum.DateTime,
|
|
79
|
+
end_time: pendulum.DateTime,
|
|
80
|
+
) -> Iterable[dict]:
|
|
81
|
+
def process_listing(listing: dict) -> dict:
|
|
82
|
+
if "latestActivityOn" in listing and listing["latestActivityOn"]:
|
|
83
|
+
try:
|
|
84
|
+
listing["latestActivityOn"] = pendulum.parse(
|
|
85
|
+
listing["latestActivityOn"]
|
|
86
|
+
)
|
|
87
|
+
except Exception:
|
|
88
|
+
listing["latestActivityOn"] = pendulum.datetime(
|
|
89
|
+
1970, 1, 1, tz="UTC"
|
|
90
|
+
)
|
|
91
|
+
else:
|
|
92
|
+
listing["latestActivityOn"] = pendulum.datetime(1970, 1, 1, tz="UTC")
|
|
93
|
+
return listing
|
|
94
|
+
|
|
95
|
+
url = f"{self.BASE_URL}/v1/listings"
|
|
96
|
+
for listing in self._paginate(url, process_item=process_listing):
|
|
97
|
+
if start_time <= listing["latestActivityOn"] <= end_time:
|
|
98
|
+
yield listing
|
|
99
|
+
|
|
100
|
+
def fetch_listing_fee_settings(
|
|
101
|
+
self,
|
|
102
|
+
listing_id,
|
|
103
|
+
start_time: pendulum.DateTime,
|
|
104
|
+
end_time: pendulum.DateTime,
|
|
105
|
+
) -> Iterable[dict]:
|
|
106
|
+
def process_fee(fee: dict) -> dict:
|
|
107
|
+
if "updatedOn" in fee and fee["updatedOn"]:
|
|
108
|
+
try:
|
|
109
|
+
fee["updatedOn"] = pendulum.parse(fee["updatedOn"])
|
|
110
|
+
except Exception:
|
|
111
|
+
fee["updatedOn"] = pendulum.datetime(1970, 1, 1, tz="UTC")
|
|
112
|
+
else:
|
|
113
|
+
fee["updatedOn"] = pendulum.datetime(1970, 1, 1, tz="UTC")
|
|
114
|
+
return fee
|
|
115
|
+
|
|
116
|
+
url = f"{self.BASE_URL}/v1/listingFeeSettings/{str(listing_id)}"
|
|
117
|
+
for fee in self._paginate(url, process_item=process_fee):
|
|
118
|
+
if start_time <= fee["updatedOn"] <= end_time:
|
|
119
|
+
yield fee
|
|
120
|
+
|
|
121
|
+
def fetch_all_listing_fee_settings(
|
|
122
|
+
self,
|
|
123
|
+
start_time: pendulum.DateTime,
|
|
124
|
+
end_time: pendulum.DateTime,
|
|
125
|
+
) -> Iterable[dict]:
|
|
126
|
+
for listing in self.fetch_listings(start_time, end_time):
|
|
127
|
+
listing_id = listing.get("id")
|
|
128
|
+
if listing_id:
|
|
129
|
+
try:
|
|
130
|
+
yield from self.fetch_listing_fee_settings(
|
|
131
|
+
listing_id, start_time, end_time
|
|
132
|
+
)
|
|
133
|
+
except Exception:
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
def fetch_listing_agreement(
|
|
137
|
+
self,
|
|
138
|
+
listing_id,
|
|
139
|
+
) -> Iterable[dict]:
|
|
140
|
+
url = f"{self.BASE_URL}/v1/listingAgreement/{str(listing_id)}"
|
|
141
|
+
yield from self._paginate(url)
|
|
142
|
+
|
|
143
|
+
def fetch_listing_pricing_settings(
|
|
144
|
+
self,
|
|
145
|
+
listing_id,
|
|
146
|
+
) -> Iterable[dict]:
|
|
147
|
+
url = f"{self.BASE_URL}/v1/listing/pricingSettings/{str(listing_id)}"
|
|
148
|
+
yield from self._paginate(url)
|
|
149
|
+
|
|
150
|
+
def fetch_all_listing_pricing_settings(
|
|
151
|
+
self,
|
|
152
|
+
start_time: pendulum.DateTime,
|
|
153
|
+
end_time: pendulum.DateTime,
|
|
154
|
+
) -> Iterable[dict]:
|
|
155
|
+
for listing in self.fetch_listings(start_time, end_time):
|
|
156
|
+
listing_id = listing.get("id")
|
|
157
|
+
if listing_id:
|
|
158
|
+
try:
|
|
159
|
+
yield from self.fetch_listing_pricing_settings(listing_id)
|
|
160
|
+
except Exception:
|
|
161
|
+
continue
|
|
162
|
+
|
|
163
|
+
def fetch_all_listing_agreements(
|
|
164
|
+
self,
|
|
165
|
+
start_time: pendulum.DateTime,
|
|
166
|
+
end_time: pendulum.DateTime,
|
|
167
|
+
) -> Iterable[dict]:
|
|
168
|
+
for listing in self.fetch_listings(start_time, end_time):
|
|
169
|
+
listing_id = listing.get("id")
|
|
170
|
+
if listing_id:
|
|
171
|
+
try:
|
|
172
|
+
yield from self.fetch_listing_agreement(listing_id)
|
|
173
|
+
except Exception:
|
|
174
|
+
continue
|
|
175
|
+
|
|
176
|
+
def fetch_cancellation_policies(self) -> Iterable[dict]:
|
|
177
|
+
url = f"{self.BASE_URL}/v1/cancellationPolicies"
|
|
178
|
+
yield from self._fetch_single(url)
|
|
179
|
+
|
|
180
|
+
def fetch_cancellation_policies_airbnb(self) -> Iterable[dict]:
|
|
181
|
+
url = f"{self.BASE_URL}/v1/cancellationPolicies/airbnb"
|
|
182
|
+
yield from self._fetch_single(url)
|
|
183
|
+
|
|
184
|
+
def fetch_cancellation_policies_marriott(self) -> Iterable[dict]:
|
|
185
|
+
url = f"{self.BASE_URL}/v1/cancellationPolicies/marriott"
|
|
186
|
+
yield from self._fetch_single(url)
|
|
187
|
+
|
|
188
|
+
def fetch_cancellation_policies_vrbo(self) -> Iterable[dict]:
|
|
189
|
+
url = f"{self.BASE_URL}/v1/cancellationPolicies/vrbo"
|
|
190
|
+
yield from self._fetch_single(url)
|
|
191
|
+
|
|
192
|
+
def fetch_reservations(self) -> Iterable[dict]:
|
|
193
|
+
url = f"{self.BASE_URL}/v1/reservations"
|
|
194
|
+
yield from self._paginate(url)
|
|
195
|
+
|
|
196
|
+
def fetch_finance_field(self, reservation_id) -> Iterable[dict]:
|
|
197
|
+
url = f"{self.BASE_URL}/v1/financeField/{str(reservation_id)}"
|
|
198
|
+
yield from self._fetch_single(url)
|
|
199
|
+
|
|
200
|
+
def fetch_all_finance_fields(self) -> Iterable[dict]:
|
|
201
|
+
for reservation in self.fetch_reservations():
|
|
202
|
+
reservation_id = reservation.get("id")
|
|
203
|
+
if reservation_id:
|
|
204
|
+
try:
|
|
205
|
+
yield from self.fetch_finance_field(reservation_id)
|
|
206
|
+
except Exception:
|
|
207
|
+
continue
|
|
208
|
+
|
|
209
|
+
def fetch_reservation_payment_methods(self) -> Iterable[dict]:
|
|
210
|
+
url = f"{self.BASE_URL}/v1/reservations/paymentMethods"
|
|
211
|
+
yield from self._fetch_single(url)
|
|
212
|
+
|
|
213
|
+
def fetch_reservation_rental_agreement(self, reservation_id) -> Iterable[dict]:
|
|
214
|
+
url = f"{self.BASE_URL}/v1/reservations/{str(reservation_id)}/rentalAgreement"
|
|
215
|
+
try:
|
|
216
|
+
yield from self._fetch_single(url)
|
|
217
|
+
except Exception:
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
def fetch_all_reservation_rental_agreements(self) -> Iterable[dict]:
|
|
221
|
+
for reservation in self.fetch_reservations():
|
|
222
|
+
reservation_id = reservation.get("id")
|
|
223
|
+
if reservation_id:
|
|
224
|
+
try:
|
|
225
|
+
yield from self.fetch_reservation_rental_agreement(reservation_id)
|
|
226
|
+
except Exception:
|
|
227
|
+
continue
|
|
228
|
+
|
|
229
|
+
def fetch_listing_calendar(self, listing_id) -> Iterable[dict]:
|
|
230
|
+
url = f"{self.BASE_URL}/v1/listings/{str(listing_id)}/calendar"
|
|
231
|
+
yield from self._fetch_single(url)
|
|
232
|
+
|
|
233
|
+
def fetch_all_listing_calendars(
|
|
234
|
+
self,
|
|
235
|
+
start_time: pendulum.DateTime,
|
|
236
|
+
end_time: pendulum.DateTime,
|
|
237
|
+
) -> Iterable[dict]:
|
|
238
|
+
for listing in self.fetch_listings(start_time, end_time):
|
|
239
|
+
listing_id = listing.get("id")
|
|
240
|
+
if listing_id:
|
|
241
|
+
try:
|
|
242
|
+
yield from self.fetch_listing_calendar(listing_id)
|
|
243
|
+
except Exception:
|
|
244
|
+
continue
|
|
245
|
+
|
|
246
|
+
def fetch_conversations(self) -> Iterable[dict]:
|
|
247
|
+
url = f"{self.BASE_URL}/v1/conversations"
|
|
248
|
+
yield from self._paginate(url)
|
|
249
|
+
|
|
250
|
+
def fetch_message_templates(self) -> Iterable[dict]:
|
|
251
|
+
url = f"{self.BASE_URL}/v1/messageTemplates"
|
|
252
|
+
yield from self._fetch_single(url)
|
|
253
|
+
|
|
254
|
+
def fetch_bed_types(self) -> Iterable[dict]:
|
|
255
|
+
url = f"{self.BASE_URL}/v1/bedTypes"
|
|
256
|
+
yield from self._fetch_single(url)
|
|
257
|
+
|
|
258
|
+
def fetch_property_types(self) -> Iterable[dict]:
|
|
259
|
+
url = f"{self.BASE_URL}/v1/propertyTypes"
|
|
260
|
+
yield from self._fetch_single(url)
|
|
261
|
+
|
|
262
|
+
def fetch_countries(self) -> Iterable[dict]:
|
|
263
|
+
url = f"{self.BASE_URL}/v1/countries"
|
|
264
|
+
yield from self._fetch_single(url)
|
|
265
|
+
|
|
266
|
+
def fetch_account_tax_settings(self) -> Iterable[dict]:
|
|
267
|
+
url = f"{self.BASE_URL}/v1/accountTaxSettings"
|
|
268
|
+
yield from self._fetch_single(url)
|
|
269
|
+
|
|
270
|
+
def fetch_user_groups(self) -> Iterable[dict]:
|
|
271
|
+
url = f"{self.BASE_URL}/v1/userGroups"
|
|
272
|
+
yield from self._fetch_single(url)
|
|
273
|
+
|
|
274
|
+
def fetch_guest_payment_charges(self) -> Iterable[dict]:
|
|
275
|
+
url = f"{self.BASE_URL}/v1/guestPayments/charges"
|
|
276
|
+
yield from self._paginate(url)
|
|
277
|
+
|
|
278
|
+
def fetch_coupons(self) -> Iterable[dict]:
|
|
279
|
+
url = f"{self.BASE_URL}/v1/coupons"
|
|
280
|
+
yield from self._fetch_single(url)
|
|
281
|
+
|
|
282
|
+
def fetch_webhook_reservations(self) -> Iterable[dict]:
|
|
283
|
+
url = f"{self.BASE_URL}/v1/webhooks/reservations"
|
|
284
|
+
yield from self._fetch_single(url)
|
|
285
|
+
|
|
286
|
+
def fetch_tasks(self) -> Iterable[dict]:
|
|
287
|
+
url = f"{self.BASE_URL}/v1/tasks"
|
|
288
|
+
yield from self._fetch_single(url)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import asyncio
|
|
2
1
|
from typing import Any, Dict, Iterable, Iterator
|
|
3
2
|
|
|
4
3
|
import aiohttp
|
|
@@ -40,51 +39,26 @@ def revenuecat_source(
|
|
|
40
39
|
yield project
|
|
41
40
|
|
|
42
41
|
@dlt.resource(
|
|
43
|
-
name="
|
|
42
|
+
name="customer_ids",
|
|
43
|
+
write_disposition="replace",
|
|
44
|
+
selected=False,
|
|
45
|
+
parallelized=True,
|
|
44
46
|
)
|
|
45
|
-
def
|
|
46
|
-
"""Get list of customers with nested purchases and subscriptions."""
|
|
47
|
+
def customer_ids():
|
|
47
48
|
if project_id is None:
|
|
48
49
|
raise ValueError("project_id is required for customers resource")
|
|
49
|
-
endpoint = f"/projects/{project_id}/customers"
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
"""Process a batch of customers with async operations."""
|
|
53
|
-
async with aiohttp.ClientSession() as session:
|
|
54
|
-
tasks = []
|
|
55
|
-
for customer in customer_batch:
|
|
56
|
-
task = process_customer_with_nested_resources_async(
|
|
57
|
-
session, api_key, project_id, customer
|
|
58
|
-
)
|
|
59
|
-
tasks.append(task)
|
|
51
|
+
yield _paginate(api_key, f"/projects/{project_id}/customers")
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if len(current_batch) >= batch_size:
|
|
72
|
-
# Process the batch asynchronously
|
|
73
|
-
processed_customers = asyncio.run(
|
|
74
|
-
process_customer_batch(current_batch)
|
|
75
|
-
)
|
|
76
|
-
for processed_customer in processed_customers:
|
|
77
|
-
yield processed_customer
|
|
78
|
-
current_batch = []
|
|
79
|
-
|
|
80
|
-
# Process any remaining customers in the final batch
|
|
81
|
-
if current_batch:
|
|
82
|
-
processed_customers = asyncio.run(process_customer_batch(current_batch))
|
|
83
|
-
for processed_customer in processed_customers:
|
|
84
|
-
yield processed_customer
|
|
85
|
-
|
|
86
|
-
# Yield each processed customer
|
|
87
|
-
yield from process_customers_sync()
|
|
53
|
+
@dlt.transformer(
|
|
54
|
+
data_from=customer_ids, write_disposition="replace", parallelized=True
|
|
55
|
+
)
|
|
56
|
+
async def customers(customers) -> Iterator[Dict[str, Any]]:
|
|
57
|
+
async with aiohttp.ClientSession() as session:
|
|
58
|
+
for customer in customers:
|
|
59
|
+
yield await process_customer_with_nested_resources_async(
|
|
60
|
+
session, api_key, project_id, customer
|
|
61
|
+
)
|
|
88
62
|
|
|
89
63
|
# Create project-dependent resources dynamically
|
|
90
64
|
project_resources = []
|
|
@@ -103,6 +77,7 @@ def revenuecat_source(
|
|
|
103
77
|
|
|
104
78
|
return [
|
|
105
79
|
projects,
|
|
80
|
+
customer_ids,
|
|
106
81
|
customers,
|
|
107
82
|
*project_resources,
|
|
108
83
|
]
|