-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb0095e
commit 6d4c695
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...cs_beta_snippets/docs_beta_snippets/guides/external-systems/apis/env_var_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import requests | ||
|
||
import dagster as dg | ||
|
||
|
||
class SunResource(dg.ConfigurableResource): | ||
latitude: float | ||
longitude: float | ||
time_zone: str | ||
|
||
@property | ||
def query_string(self) -> str: | ||
return f"https://api.sunrise-sunset.org/json?lat={self.latitude}&lng={self.longitude}&date=today&tzid={self.time_zone}" | ||
|
||
def sunrise(self) -> str: | ||
data = requests.get(self.query_string, timeout=5).json() | ||
return data["results"]["sunrise"] | ||
|
||
|
||
# highlight-start | ||
@dg.asset | ||
def home_sunrise(context: dg.AssetExecutionContext, sun_resource: SunResource) -> None: | ||
sunrise = sun_resource.sunrise() | ||
context.log.info(f"Sunrise at home is at {sunrise}.") | ||
|
||
|
||
defs = dg.Definitions( | ||
assets=[home_sunrise], | ||
resources={ | ||
"sun_resource": SunResource( | ||
latitude=float(dg.EnvVar("HOME_LATITUDE")), | ||
longitude=float(dg.EnvVar("HOME_LONGITUDE")), | ||
time_zone=dg.EnvVar("HOME_TIMEZONE"), | ||
) | ||
}, | ||
) | ||
|
||
# highlight-end |