Skip to content

Instantly share code, notes, and snippets.

@isaacharrisholt
Last active June 19, 2022 11:37
Show Gist options
  • Select an option

  • Save isaacharrisholt/7a67fc3975bc3479d60524164bf669d0 to your computer and use it in GitHub Desktop.

Select an option

Save isaacharrisholt/7a67fc3975bc3479d60524164bf669d0 to your computer and use it in GitHub Desktop.
Dagster graph with Dagstd
import zipfile
from datetime import datetime
from dagster import op, job
from dagstd.constants import Constant, Five
from dagstd.operations import fmt
@op
def get_todays_date_string() -> str:
return datetime.today().strftime("%Y-%m-%d")
@op
def extract_file_from_zip(context, zip_path: str, file_name: str) -> str:
with zipfile.ZipFile(zip_path) as zip_file:
with(f'/tmp/{file_name}', 'wb') as f:
f.write(zip_file.read(file_name))
context.log.info(f'Extracted {file_name} from {zip_path}')
return f'/tmp/{file_name}'
@job
def process_data():
date = get_todays_date_string()
url = fmt(Constant('https://example.com/{}.csv'), [date])
zip_path = download_large_file(url)
file_name = fmt(Constant('file_{}.txt'), [Five()])
file_path = extract_file_from_zip(zip_path, file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment