Skip to content

Commit a040583

Browse files
committed
fix(coat): add s3 storage
1 parent 0eb358d commit a040583

1 file changed

Lines changed: 51 additions & 8 deletions

File tree

src/datasync/coat.py

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import dlt
22
import typer
3+
from dlt.destinations.impl.filesystem.factory import filesystem
4+
from dlt.sources.credentials import AwsCredentials
35
from dlt.sources.helpers.rest_client import RESTClient
46
from dlt.sources.helpers.rest_client.auth import BearerTokenAuth
57
from dlt.sources.helpers.rest_client.paginators import OffsetPaginator
@@ -104,10 +106,35 @@ def plausible_source(api_key: str, site_id: str = PLAUSIBLE_SITE_ID):
104106

105107
@app.command()
106108
def get_plausible_analytics(
107-
bucket_url: str = typer.Option(
108-
default="data",
109-
envvar="COAT_BUCKET_URL",
110-
help="Destination bucket URL (local path or s3://...)",
109+
endpoint_url: str = typer.Option(
110+
...,
111+
envvar="COAT_AWS_ENDPOINT",
112+
help="AWS S3 endpoint URL",
113+
),
114+
access_key: str = typer.Option(
115+
...,
116+
envvar="COAT_AWS_ACCESS_KEY",
117+
help="AWS S3 access key",
118+
),
119+
secret_key: str = typer.Option(
120+
...,
121+
envvar="COAT_AWS_SECRET_KEY",
122+
help="AWS S3 secret key",
123+
),
124+
bucket: str = typer.Option(
125+
...,
126+
envvar="COAT_AWS_BUCKET",
127+
help="AWS S3 bucket name",
128+
),
129+
prefix: str = typer.Option(
130+
default="coat",
131+
envvar="COAT_S3_PREFIX",
132+
help="AWS S3 prefix (folder path) for storing data",
133+
),
134+
region: str = typer.Option(
135+
default="us-east-1",
136+
envvar="COAT_S3_REGION",
137+
help="AWS S3 region",
111138
),
112139
api_key: str = typer.Option(
113140
...,
@@ -121,17 +148,33 @@ def get_plausible_analytics(
121148
),
122149
):
123150
"""Run the Plausible analytics pipeline for data.coat.no."""
151+
bucket_url = f"s3://{bucket}/{prefix}"
152+
credentials = AwsCredentials(
153+
s3_url_style="path",
154+
endpoint_url=endpoint_url,
155+
aws_access_key_id=access_key,
156+
aws_secret_access_key=secret_key,
157+
region_name=region,
158+
)
159+
160+
filesystem_destination = filesystem(
161+
bucket_url=bucket_url,
162+
credentials=credentials,
163+
layout="{table_name}.{ext}",
164+
)
165+
124166
pipeline = dlt.pipeline(
125167
pipeline_name="coat_plausible",
126-
destination=dlt.destinations.filesystem(
127-
bucket_url=bucket_url, layout="{table_name}.{ext}"
128-
),
168+
destination=filesystem_destination,
129169
dataset_name="coat_plausible",
130170
)
131-
pipeline.run(
171+
172+
load_info = pipeline.run(
132173
plausible_source(api_key=api_key, site_id=site_id),
133174
loader_file_format="parquet",
134175
)
176+
177+
log.info(f"Pipeline run info: {load_info}")
135178
log.info(f"Plausible pipeline complete. Data at: {bucket_url}/coat_plausible")
136179

137180

0 commit comments

Comments
 (0)