omniload 0.0.0.dev0__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.
- omniload/conftest.py +72 -0
- omniload/main.py +810 -0
- omniload/src/.gitignore +10 -0
- omniload/src/adjust/__init__.py +108 -0
- omniload/src/adjust/adjust_helpers.py +122 -0
- omniload/src/airtable/__init__.py +84 -0
- omniload/src/allium/__init__.py +128 -0
- omniload/src/anthropic/__init__.py +277 -0
- omniload/src/anthropic/helpers.py +525 -0
- omniload/src/applovin/__init__.py +316 -0
- omniload/src/applovin_max/__init__.py +117 -0
- omniload/src/appsflyer/__init__.py +325 -0
- omniload/src/appsflyer/client.py +110 -0
- omniload/src/appstore/__init__.py +142 -0
- omniload/src/appstore/client.py +126 -0
- omniload/src/appstore/errors.py +15 -0
- omniload/src/appstore/models.py +117 -0
- omniload/src/appstore/resources.py +179 -0
- omniload/src/arrow/__init__.py +81 -0
- omniload/src/asana_source/__init__.py +281 -0
- omniload/src/asana_source/helpers.py +30 -0
- omniload/src/asana_source/settings.py +158 -0
- omniload/src/attio/__init__.py +102 -0
- omniload/src/attio/helpers.py +65 -0
- omniload/src/blob.py +95 -0
- omniload/src/bruin/__init__.py +76 -0
- omniload/src/chess/__init__.py +180 -0
- omniload/src/chess/helpers.py +35 -0
- omniload/src/chess/settings.py +18 -0
- omniload/src/clickup/__init__.py +85 -0
- omniload/src/clickup/helpers.py +47 -0
- omniload/src/collector/spinner.py +43 -0
- omniload/src/couchbase_source/__init__.py +118 -0
- omniload/src/couchbase_source/helpers.py +135 -0
- omniload/src/cursor/__init__.py +83 -0
- omniload/src/cursor/helpers.py +188 -0
- omniload/src/customer_io/__init__.py +486 -0
- omniload/src/customer_io/helpers.py +530 -0
- omniload/src/destinations.py +982 -0
- omniload/src/docebo/__init__.py +589 -0
- omniload/src/docebo/client.py +435 -0
- omniload/src/docebo/helpers.py +97 -0
- omniload/src/dune/__init__.py +104 -0
- omniload/src/dune/helpers.py +108 -0
- omniload/src/dynamodb/__init__.py +86 -0
- omniload/src/elasticsearch/__init__.py +80 -0
- omniload/src/elasticsearch/helpers.py +141 -0
- omniload/src/errors.py +26 -0
- omniload/src/facebook_ads/__init__.py +403 -0
- omniload/src/facebook_ads/exceptions.py +19 -0
- omniload/src/facebook_ads/helpers.py +296 -0
- omniload/src/facebook_ads/settings.py +224 -0
- omniload/src/facebook_ads/utils.py +53 -0
- omniload/src/factory.py +305 -0
- omniload/src/filesystem/__init__.py +133 -0
- omniload/src/filesystem/helpers.py +114 -0
- omniload/src/filesystem/readers.py +187 -0
- omniload/src/filters.py +62 -0
- omniload/src/fireflies/__init__.py +151 -0
- omniload/src/fireflies/helpers.py +753 -0
- omniload/src/fluxx/__init__.py +10013 -0
- omniload/src/fluxx/helpers.py +233 -0
- omniload/src/frankfurter/__init__.py +157 -0
- omniload/src/frankfurter/helpers.py +48 -0
- omniload/src/freshdesk/__init__.py +103 -0
- omniload/src/freshdesk/freshdesk_client.py +151 -0
- omniload/src/freshdesk/settings.py +23 -0
- omniload/src/fundraiseup/__init__.py +95 -0
- omniload/src/fundraiseup/client.py +81 -0
- omniload/src/github/__init__.py +202 -0
- omniload/src/github/helpers.py +207 -0
- omniload/src/github/queries.py +129 -0
- omniload/src/github/settings.py +24 -0
- omniload/src/google_ads/__init__.py +198 -0
- omniload/src/google_ads/field.py +17 -0
- omniload/src/google_ads/metrics.py +254 -0
- omniload/src/google_ads/predicates.py +37 -0
- omniload/src/google_ads/reports.py +411 -0
- omniload/src/google_ads/test_google_ads.py +184 -0
- omniload/src/google_analytics/__init__.py +144 -0
- omniload/src/google_analytics/helpers.py +312 -0
- omniload/src/google_sheets/README.md +95 -0
- omniload/src/google_sheets/__init__.py +166 -0
- omniload/src/google_sheets/helpers/__init__.py +15 -0
- omniload/src/google_sheets/helpers/api_calls.py +160 -0
- omniload/src/google_sheets/helpers/data_processing.py +316 -0
- omniload/src/gorgias/__init__.py +595 -0
- omniload/src/gorgias/helpers.py +166 -0
- omniload/src/hostaway/__init__.py +302 -0
- omniload/src/hostaway/client.py +288 -0
- omniload/src/http/__init__.py +38 -0
- omniload/src/http/readers.py +146 -0
- omniload/src/http_client.py +24 -0
- omniload/src/hubspot/__init__.py +800 -0
- omniload/src/hubspot/helpers.py +417 -0
- omniload/src/hubspot/settings.py +329 -0
- omniload/src/indeed/__init__.py +153 -0
- omniload/src/indeed/helpers.py +228 -0
- omniload/src/influxdb/__init__.py +46 -0
- omniload/src/influxdb/client.py +34 -0
- omniload/src/intercom/__init__.py +142 -0
- omniload/src/intercom/helpers.py +674 -0
- omniload/src/intercom/settings.py +279 -0
- omniload/src/isoc_pulse/__init__.py +159 -0
- omniload/src/jira_source/__init__.py +377 -0
- omniload/src/jira_source/helpers.py +510 -0
- omniload/src/jira_source/settings.py +184 -0
- omniload/src/kafka/__init__.py +120 -0
- omniload/src/kafka/helpers.py +241 -0
- omniload/src/kinesis/__init__.py +153 -0
- omniload/src/kinesis/helpers.py +96 -0
- omniload/src/klaviyo/__init__.py +237 -0
- omniload/src/klaviyo/client.py +212 -0
- omniload/src/klaviyo/helpers.py +19 -0
- omniload/src/linear/__init__.py +634 -0
- omniload/src/linear/helpers.py +111 -0
- omniload/src/linkedin_ads/__init__.py +266 -0
- omniload/src/linkedin_ads/dimension_time_enum.py +17 -0
- omniload/src/linkedin_ads/helpers.py +246 -0
- omniload/src/loader.py +69 -0
- omniload/src/mailchimp/__init__.py +126 -0
- omniload/src/mailchimp/helpers.py +226 -0
- omniload/src/mailchimp/settings.py +164 -0
- omniload/src/masking.py +344 -0
- omniload/src/mixpanel/__init__.py +62 -0
- omniload/src/mixpanel/client.py +104 -0
- omniload/src/monday/__init__.py +246 -0
- omniload/src/monday/helpers.py +392 -0
- omniload/src/monday/settings.py +325 -0
- omniload/src/mongodb/__init__.py +281 -0
- omniload/src/mongodb/helpers.py +975 -0
- omniload/src/notion/__init__.py +69 -0
- omniload/src/notion/helpers/__init__.py +14 -0
- omniload/src/notion/helpers/client.py +178 -0
- omniload/src/notion/helpers/database.py +92 -0
- omniload/src/notion/settings.py +17 -0
- omniload/src/partition.py +32 -0
- omniload/src/personio/__init__.py +345 -0
- omniload/src/personio/helpers.py +100 -0
- omniload/src/phantombuster/__init__.py +65 -0
- omniload/src/phantombuster/client.py +87 -0
- omniload/src/pinterest/__init__.py +82 -0
- omniload/src/pipedrive/__init__.py +212 -0
- omniload/src/pipedrive/helpers/__init__.py +37 -0
- omniload/src/pipedrive/helpers/custom_fields_munger.py +116 -0
- omniload/src/pipedrive/helpers/pages.py +129 -0
- omniload/src/pipedrive/settings.py +41 -0
- omniload/src/pipedrive/typing.py +17 -0
- omniload/src/plusvibeai/__init__.py +335 -0
- omniload/src/plusvibeai/helpers.py +544 -0
- omniload/src/plusvibeai/settings.py +252 -0
- omniload/src/primer/__init__.py +45 -0
- omniload/src/primer/helpers.py +79 -0
- omniload/src/quickbooks/__init__.py +117 -0
- omniload/src/reddit_ads/__init__.py +183 -0
- omniload/src/reddit_ads/helpers.py +232 -0
- omniload/src/resource.py +40 -0
- omniload/src/revenuecat/__init__.py +83 -0
- omniload/src/revenuecat/helpers.py +237 -0
- omniload/src/salesforce/__init__.py +170 -0
- omniload/src/salesforce/helpers.py +78 -0
- omniload/src/shopify/__init__.py +1953 -0
- omniload/src/shopify/exceptions.py +17 -0
- omniload/src/shopify/helpers.py +202 -0
- omniload/src/shopify/settings.py +19 -0
- omniload/src/slack/__init__.py +290 -0
- omniload/src/slack/helpers.py +218 -0
- omniload/src/slack/settings.py +36 -0
- omniload/src/smartsheets/__init__.py +82 -0
- omniload/src/snapchat_ads/__init__.py +455 -0
- omniload/src/snapchat_ads/client.py +72 -0
- omniload/src/snapchat_ads/helpers.py +630 -0
- omniload/src/snapchat_ads/settings.py +130 -0
- omniload/src/socrata_source/__init__.py +83 -0
- omniload/src/socrata_source/helpers.py +85 -0
- omniload/src/socrata_source/settings.py +8 -0
- omniload/src/solidgate/__init__.py +219 -0
- omniload/src/solidgate/helpers.py +154 -0
- omniload/src/sources.py +5408 -0
- omniload/src/sql_database/__init__.py +0 -0
- omniload/src/sql_database/callbacks.py +66 -0
- omniload/src/stripe_analytics/__init__.py +183 -0
- omniload/src/stripe_analytics/helpers.py +386 -0
- omniload/src/stripe_analytics/settings.py +80 -0
- omniload/src/table_definition.py +15 -0
- omniload/src/testdata/fakebqcredentials.json +14 -0
- omniload/src/tiktok_ads/__init__.py +150 -0
- omniload/src/tiktok_ads/tiktok_helpers.py +130 -0
- omniload/src/time.py +11 -0
- omniload/src/trustpilot/__init__.py +48 -0
- omniload/src/trustpilot/client.py +48 -0
- omniload/src/version.py +6 -0
- omniload/src/wise/__init__.py +68 -0
- omniload/src/wise/client.py +63 -0
- omniload/src/zendesk/__init__.py +480 -0
- omniload/src/zendesk/helpers/__init__.py +39 -0
- omniload/src/zendesk/helpers/api_helpers.py +119 -0
- omniload/src/zendesk/helpers/credentials.py +68 -0
- omniload/src/zendesk/helpers/talk_api.py +132 -0
- omniload/src/zendesk/settings.py +71 -0
- omniload/src/zoom/__init__.py +99 -0
- omniload/src/zoom/helpers.py +102 -0
- omniload/testdata/.gitignore +2 -0
- omniload/testdata/create_replace.csv +21 -0
- omniload/testdata/delete_insert_expected.csv +6 -0
- omniload/testdata/delete_insert_part1.csv +5 -0
- omniload/testdata/delete_insert_part2.csv +6 -0
- omniload/testdata/merge_expected.csv +5 -0
- omniload/testdata/merge_part1.csv +4 -0
- omniload/testdata/merge_part2.csv +5 -0
- omniload/tests/unit/test_smartsheets.py +133 -0
- omniload-0.0.0.dev0.dist-info/METADATA +439 -0
- omniload-0.0.0.dev0.dist-info/RECORD +218 -0
- omniload-0.0.0.dev0.dist-info/WHEEL +4 -0
- omniload-0.0.0.dev0.dist-info/entry_points.txt +2 -0
- omniload-0.0.0.dev0.dist-info/licenses/LICENSE.Apache-2.0 +201 -0
- omniload-0.0.0.dev0.dist-info/licenses/LICENSE.md +21 -0
- omniload-0.0.0.dev0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
from datetime import datetime, timedelta, timezone
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
import dlt
|
|
6
|
+
from dlt.sources.rest_api import EndpointResource, RESTAPIConfig, rest_api_resources
|
|
7
|
+
from requests import Response
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class InvalidCustomReportError(Exception):
|
|
11
|
+
def __init__(self):
|
|
12
|
+
super().__init__(
|
|
13
|
+
"Custom report should be in the format 'custom:{endpoint}:{report_type}:{dimensions}"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ClientError(Exception):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
TYPE_HINTS = {
|
|
22
|
+
"application_is_hidden": {"data_type": "bool"},
|
|
23
|
+
"average_cpa": {"data_type": "double"},
|
|
24
|
+
"average_cpc": {"data_type": "double"},
|
|
25
|
+
"campaign_bid_goal": {"data_type": "double"},
|
|
26
|
+
"campaign_roas_goal": {"data_type": "double"},
|
|
27
|
+
"clicks": {"data_type": "bigint"},
|
|
28
|
+
"conversions": {"data_type": "bigint"},
|
|
29
|
+
"conversion_rate": {"data_type": "double"},
|
|
30
|
+
"cost": {"data_type": "double"}, # assuming float.
|
|
31
|
+
"ctr": {"data_type": "double"},
|
|
32
|
+
"day": {"data_type": "date"},
|
|
33
|
+
"first_purchase": {"data_type": "bigint"},
|
|
34
|
+
"ecpm": {"data_type": "double"},
|
|
35
|
+
"impressions": {"data_type": "bigint"},
|
|
36
|
+
"installs": {"data_type": "bigint"},
|
|
37
|
+
"revenue": {"data_type": "double"},
|
|
38
|
+
"redownloads": {"data_type": "bigint"},
|
|
39
|
+
"sales": {"data_type": "double"}, # assuming float.
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ReportType(Enum):
|
|
44
|
+
PUBLISHER = "publisher"
|
|
45
|
+
ADVERTISER = "advertiser"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
REPORT_SCHEMA: Dict[ReportType, List[str]] = {
|
|
49
|
+
ReportType.PUBLISHER: [
|
|
50
|
+
"ad_type",
|
|
51
|
+
"application",
|
|
52
|
+
"application_is_hidden",
|
|
53
|
+
"bidding_integration",
|
|
54
|
+
"clicks",
|
|
55
|
+
"country",
|
|
56
|
+
"ctr",
|
|
57
|
+
"day",
|
|
58
|
+
"device_type",
|
|
59
|
+
"ecpm",
|
|
60
|
+
"hour",
|
|
61
|
+
"impressions",
|
|
62
|
+
"package_name",
|
|
63
|
+
"placement_type",
|
|
64
|
+
"platform",
|
|
65
|
+
"revenue",
|
|
66
|
+
"size",
|
|
67
|
+
"store_id",
|
|
68
|
+
"zone",
|
|
69
|
+
"zone_id",
|
|
70
|
+
],
|
|
71
|
+
ReportType.ADVERTISER: [
|
|
72
|
+
"ad",
|
|
73
|
+
"ad_creative_type",
|
|
74
|
+
"ad_id",
|
|
75
|
+
"ad_type",
|
|
76
|
+
"average_cpa",
|
|
77
|
+
"average_cpc",
|
|
78
|
+
"campaign",
|
|
79
|
+
"campaign_ad_type",
|
|
80
|
+
"campaign_bid_goal",
|
|
81
|
+
"campaign_id_external",
|
|
82
|
+
"campaign_package_name",
|
|
83
|
+
"campaign_roas_goal",
|
|
84
|
+
"campaign_store_id",
|
|
85
|
+
"campaign_type",
|
|
86
|
+
"clicks",
|
|
87
|
+
"conversions",
|
|
88
|
+
"conversion_rate",
|
|
89
|
+
"cost",
|
|
90
|
+
"country",
|
|
91
|
+
"creative_set",
|
|
92
|
+
"creative_set_id",
|
|
93
|
+
"ctr",
|
|
94
|
+
"custom_page_id",
|
|
95
|
+
"day",
|
|
96
|
+
"device_type",
|
|
97
|
+
"external_placement_id",
|
|
98
|
+
"first_purchase",
|
|
99
|
+
"hour",
|
|
100
|
+
"impressions",
|
|
101
|
+
"installs",
|
|
102
|
+
"optimization_day_target",
|
|
103
|
+
"placement_type",
|
|
104
|
+
"platform",
|
|
105
|
+
"redownloads",
|
|
106
|
+
"sales",
|
|
107
|
+
"size",
|
|
108
|
+
"target_event",
|
|
109
|
+
"traffic_source",
|
|
110
|
+
],
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# Columns to exclude from probabilistic reports
|
|
114
|
+
PROBABILISTIC_REPORT_EXCLUDE = ["installs", "redownloads"]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Dimensions that can be used in merge_key (excludes metrics)
|
|
118
|
+
DIMENSIONS = {
|
|
119
|
+
# Publisher dimensions
|
|
120
|
+
"ad_type",
|
|
121
|
+
"application",
|
|
122
|
+
"application_is_hidden",
|
|
123
|
+
"bidding_integration",
|
|
124
|
+
"country",
|
|
125
|
+
"day",
|
|
126
|
+
"device_type",
|
|
127
|
+
"hour",
|
|
128
|
+
"package_name",
|
|
129
|
+
"placement_type",
|
|
130
|
+
"platform",
|
|
131
|
+
"size",
|
|
132
|
+
"store_id",
|
|
133
|
+
"zone",
|
|
134
|
+
"zone_id",
|
|
135
|
+
# Advertiser dimensions
|
|
136
|
+
"ad",
|
|
137
|
+
"ad_creative_type",
|
|
138
|
+
"ad_id",
|
|
139
|
+
"campaign",
|
|
140
|
+
"campaign_ad_type",
|
|
141
|
+
"campaign_id_external",
|
|
142
|
+
"campaign_package_name",
|
|
143
|
+
"campaign_store_id",
|
|
144
|
+
"campaign_type",
|
|
145
|
+
"creative_set",
|
|
146
|
+
"creative_set_id",
|
|
147
|
+
"custom_page_id",
|
|
148
|
+
"external_placement_id",
|
|
149
|
+
"optimization_day_target",
|
|
150
|
+
"target_event",
|
|
151
|
+
"traffic_source",
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@dlt.source
|
|
156
|
+
def applovin_source(
|
|
157
|
+
api_key: str,
|
|
158
|
+
start_date: str,
|
|
159
|
+
end_date: Optional[str],
|
|
160
|
+
custom: Optional[str],
|
|
161
|
+
):
|
|
162
|
+
if end_date is None:
|
|
163
|
+
# use the greatest of yesterday and start_date
|
|
164
|
+
end_date = max(
|
|
165
|
+
datetime.now(timezone.utc) - timedelta(days=1),
|
|
166
|
+
datetime.fromisoformat(start_date).replace(tzinfo=timezone.utc),
|
|
167
|
+
).strftime("%Y-%m-%d")
|
|
168
|
+
|
|
169
|
+
config: RESTAPIConfig = {
|
|
170
|
+
"client": {
|
|
171
|
+
"base_url": "https://r.applovin.com/",
|
|
172
|
+
"auth": {
|
|
173
|
+
"type": "api_key",
|
|
174
|
+
"name": "api_key",
|
|
175
|
+
"location": "query",
|
|
176
|
+
"api_key": api_key,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
"resource_defaults": {
|
|
180
|
+
"write_disposition": "merge",
|
|
181
|
+
"endpoint": {
|
|
182
|
+
"incremental": {
|
|
183
|
+
"cursor_path": "day",
|
|
184
|
+
"start_param": "start",
|
|
185
|
+
"end_param": "end",
|
|
186
|
+
"initial_value": start_date,
|
|
187
|
+
"end_value": end_date,
|
|
188
|
+
"range_start": "closed",
|
|
189
|
+
"range_end": "closed",
|
|
190
|
+
},
|
|
191
|
+
"params": {
|
|
192
|
+
"format": "json",
|
|
193
|
+
},
|
|
194
|
+
"paginator": "single_page",
|
|
195
|
+
"response_actions": [
|
|
196
|
+
http_error_handler,
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
"resources": [
|
|
201
|
+
resource(
|
|
202
|
+
"publisher-report",
|
|
203
|
+
"report",
|
|
204
|
+
REPORT_SCHEMA[ReportType.PUBLISHER],
|
|
205
|
+
ReportType.PUBLISHER,
|
|
206
|
+
),
|
|
207
|
+
resource(
|
|
208
|
+
"advertiser-report",
|
|
209
|
+
"report",
|
|
210
|
+
REPORT_SCHEMA[ReportType.ADVERTISER],
|
|
211
|
+
ReportType.ADVERTISER,
|
|
212
|
+
),
|
|
213
|
+
resource(
|
|
214
|
+
"advertiser-probabilistic-report",
|
|
215
|
+
"probabilisticReport",
|
|
216
|
+
exclude(
|
|
217
|
+
REPORT_SCHEMA[ReportType.ADVERTISER], PROBABILISTIC_REPORT_EXCLUDE
|
|
218
|
+
),
|
|
219
|
+
ReportType.ADVERTISER,
|
|
220
|
+
day_only_merge_key=True,
|
|
221
|
+
),
|
|
222
|
+
resource(
|
|
223
|
+
"advertiser-ska-report",
|
|
224
|
+
"skaReport",
|
|
225
|
+
REPORT_SCHEMA[ReportType.ADVERTISER],
|
|
226
|
+
ReportType.ADVERTISER,
|
|
227
|
+
day_only_merge_key=True,
|
|
228
|
+
),
|
|
229
|
+
],
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if custom:
|
|
233
|
+
custom_report = custom_report_from_spec(custom)
|
|
234
|
+
config["resources"].append(custom_report)
|
|
235
|
+
|
|
236
|
+
yield from rest_api_resources(config)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def resource(
|
|
240
|
+
name: str,
|
|
241
|
+
endpoint: str,
|
|
242
|
+
dimensions: List[str],
|
|
243
|
+
report_type: ReportType,
|
|
244
|
+
day_only_merge_key: bool = False,
|
|
245
|
+
) -> EndpointResource:
|
|
246
|
+
# For probabilistic and SKA reports use only "day" as merge_key
|
|
247
|
+
# because other dimensions may return null values
|
|
248
|
+
merge_key: str | List[str] = "day"
|
|
249
|
+
|
|
250
|
+
if not day_only_merge_key:
|
|
251
|
+
merge_key_parts: List[str] = []
|
|
252
|
+
if "day" in dimensions:
|
|
253
|
+
merge_key_parts.append("day")
|
|
254
|
+
|
|
255
|
+
for dim in dimensions:
|
|
256
|
+
if dim in DIMENSIONS and dim not in merge_key_parts:
|
|
257
|
+
merge_key_parts.append(dim)
|
|
258
|
+
|
|
259
|
+
# If no dimensions found, default to "day"
|
|
260
|
+
if merge_key_parts:
|
|
261
|
+
merge_key = (
|
|
262
|
+
merge_key_parts[0] if len(merge_key_parts) == 1 else merge_key_parts
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
"name": name,
|
|
267
|
+
"columns": build_type_hints(dimensions),
|
|
268
|
+
"merge_key": merge_key,
|
|
269
|
+
"endpoint": {
|
|
270
|
+
"path": endpoint,
|
|
271
|
+
"params": {
|
|
272
|
+
"report_type": report_type.value,
|
|
273
|
+
"columns": ",".join(dimensions),
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def custom_report_from_spec(spec: str) -> EndpointResource:
|
|
280
|
+
parts = spec.split(":")
|
|
281
|
+
if len(parts) != 4:
|
|
282
|
+
raise InvalidCustomReportError()
|
|
283
|
+
|
|
284
|
+
_, endpoint, report, dims = parts
|
|
285
|
+
report_type = ReportType(report.strip())
|
|
286
|
+
dimensions = validate_dimensions(dims)
|
|
287
|
+
endpoint = endpoint.strip()
|
|
288
|
+
|
|
289
|
+
return resource(
|
|
290
|
+
name="custom_report",
|
|
291
|
+
endpoint=endpoint,
|
|
292
|
+
dimensions=dimensions,
|
|
293
|
+
report_type=report_type,
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def validate_dimensions(dimensions: str) -> List[str]:
|
|
298
|
+
dims = [dim.strip() for dim in dimensions.split(",")]
|
|
299
|
+
|
|
300
|
+
if "day" not in dims:
|
|
301
|
+
dims.append("day")
|
|
302
|
+
|
|
303
|
+
return dims
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def build_type_hints(cols: List[str]) -> dict:
|
|
307
|
+
return {col: TYPE_HINTS[col] for col in cols if col in TYPE_HINTS}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def exclude(dimensions: List[str], excludes: List[str]) -> List[str]:
|
|
311
|
+
return [dim for dim in dimensions if dim not in excludes]
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def http_error_handler(resp: Response):
|
|
315
|
+
if not resp.ok:
|
|
316
|
+
raise ClientError(f"HTTP Status {resp.status_code}: {resp.text}")
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
from typing import Iterator
|
|
3
|
+
|
|
4
|
+
import dlt
|
|
5
|
+
import pandas as pd # type: ignore[import-untyped]
|
|
6
|
+
import pendulum
|
|
7
|
+
import requests
|
|
8
|
+
from dlt.sources import DltResource
|
|
9
|
+
from dlt.sources.helpers.requests import Client
|
|
10
|
+
from pendulum.date import Date
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dlt.source(max_table_nesting=0)
|
|
14
|
+
def applovin_max_source(
|
|
15
|
+
start_date: Date,
|
|
16
|
+
applications: list[str],
|
|
17
|
+
api_key: str,
|
|
18
|
+
end_date: Date | None,
|
|
19
|
+
) -> DltResource:
|
|
20
|
+
@dlt.resource(
|
|
21
|
+
name="user_ad_revenue",
|
|
22
|
+
write_disposition="merge",
|
|
23
|
+
merge_key="partition_date",
|
|
24
|
+
columns={
|
|
25
|
+
"partition_date": {"data_type": "date", "partition": True},
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
def fetch_ad_revenue_report(
|
|
29
|
+
dateTime=(
|
|
30
|
+
dlt.sources.incremental(
|
|
31
|
+
"partition_date",
|
|
32
|
+
initial_value=start_date,
|
|
33
|
+
end_value=end_date,
|
|
34
|
+
range_start="closed",
|
|
35
|
+
range_end="closed",
|
|
36
|
+
)
|
|
37
|
+
),
|
|
38
|
+
) -> Iterator[dict]:
|
|
39
|
+
url = "https://r.applovin.com/max/userAdRevenueReport"
|
|
40
|
+
start_date = dateTime.last_value
|
|
41
|
+
|
|
42
|
+
if dateTime.end_value is None:
|
|
43
|
+
end_date = (pendulum.yesterday("UTC")).date()
|
|
44
|
+
else:
|
|
45
|
+
end_date = dateTime.end_value
|
|
46
|
+
|
|
47
|
+
client = create_client()
|
|
48
|
+
platforms = ["ios", "android", "fireos"]
|
|
49
|
+
|
|
50
|
+
for app in applications:
|
|
51
|
+
current_date = start_date
|
|
52
|
+
while current_date <= end_date:
|
|
53
|
+
for platform in platforms:
|
|
54
|
+
df = get_data(
|
|
55
|
+
url=url,
|
|
56
|
+
current_date=current_date,
|
|
57
|
+
application=app,
|
|
58
|
+
api_key=api_key,
|
|
59
|
+
client=client,
|
|
60
|
+
platform=platform,
|
|
61
|
+
)
|
|
62
|
+
if df is not None:
|
|
63
|
+
yield df
|
|
64
|
+
current_date = current_date + timedelta(days=1)
|
|
65
|
+
|
|
66
|
+
return fetch_ad_revenue_report
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def create_client() -> requests.Session:
|
|
70
|
+
return Client(
|
|
71
|
+
raise_for_status=False,
|
|
72
|
+
retry_condition=retry_on_limit,
|
|
73
|
+
request_max_attempts=12,
|
|
74
|
+
).session
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def retry_on_limit(
|
|
78
|
+
response: requests.Response | None, exception: BaseException | None
|
|
79
|
+
) -> bool:
|
|
80
|
+
if response is None:
|
|
81
|
+
return False
|
|
82
|
+
return response.status_code == 429
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_data(
|
|
86
|
+
url: str,
|
|
87
|
+
current_date: Date,
|
|
88
|
+
application: str,
|
|
89
|
+
api_key: str,
|
|
90
|
+
platform: str,
|
|
91
|
+
client: requests.Session,
|
|
92
|
+
):
|
|
93
|
+
params = {
|
|
94
|
+
"api_key": api_key,
|
|
95
|
+
"date": current_date.isoformat(),
|
|
96
|
+
"platform": platform,
|
|
97
|
+
"application": application,
|
|
98
|
+
"aggregated": "false",
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
response = client.get(url=url, params=params)
|
|
102
|
+
|
|
103
|
+
if response.status_code != 200:
|
|
104
|
+
if response.status_code == 404:
|
|
105
|
+
if "No Mediation App Id found for platform" in response.text:
|
|
106
|
+
return None
|
|
107
|
+
error_message = (
|
|
108
|
+
f"AppLovin MAX API error (status {response.status_code}): {response.text}"
|
|
109
|
+
)
|
|
110
|
+
raise requests.HTTPError(error_message)
|
|
111
|
+
|
|
112
|
+
response_url = response.json().get("ad_revenue_report_url")
|
|
113
|
+
df = pd.read_csv(response_url)
|
|
114
|
+
df["Date"] = pd.to_datetime(df["Date"])
|
|
115
|
+
df["partition_date"] = df["Date"].dt.date
|
|
116
|
+
df["platform"] = platform
|
|
117
|
+
return df
|