Welcome to Sun Stream
Generates a sequence of sun-rise and sun-set actions
Example:
# Announcing the sun-rises and sun-sets at Mt. Everest:
for action in sun_stream(27.986065, 86.922623, include_now=False):
if action == SunAction.RISE:
print("Sun rises at Mt. Everest")
else:
print("Sun sets at Mt. Everest")
To set desktop colorscheme according to diurnal pattern in Plasma:
for action in sun_stream(27.986065, 86.922623, include_now=True):
if action == SunAction.RISE:
subprocess.run(["plasma-apply-colorscheme", "BreezeLight"])
else:
subprocess.run(["plasma-apply-colorscheme", "BreezeDark"])
In this example, having include_now being True provides a little
convenience, that the iterable yields immediately the current state of
the sun (or the latest rise/set action before now), so the program takes
effect setting the appropriate theme first thing after launching, instead
of waiting for the next event to happen.
SunAction
Bases: enum.Enum
Two actions of the sun: RISE and SET.
Source code in sun_stream/__init__.py
42 43 44 45 46 | |
sun_stream(latitude, longitude, include_now=True)
Yield a sequence of sun-rise and sun-set actions at the time it happens
This function fetches the time of the solar pattern from https://sunrise-sunset.org/, and will only issue requests when needed.
If include_now is set to True, the state of now is instantly yielded. For
example, if the current moment is midnight, the first action would be
SunAction.SET; if the current moment is at noon, the first action would be
SunAction.RISE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude |
float
|
the latitude of the place. |
required |
longitude |
float
|
the longtiude of the place. |
required |
include_now |
bool
|
whether to include the sun's state at the current moment.
Defaults to |
True
|
Yields:
| Name | Type | Description |
|---|---|---|
SunAction |
Iterable[SunAction]
|
The sun's action at the moment. |
Source code in sun_stream/__init__.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |