Skip to content

Commit bff1bf2

Browse files
committed
improved
1 parent a40fe36 commit bff1bf2

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

sphinx/v3/code-recipes.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,15 @@ The `raw_measurements_dict` contains multiple sub-dicts, each one being a a data
666666

667667
With the OneCall Api you can get the current weather, hourly forecast for the next 48 hours and the daily forecast for the next seven days in one call.
668668

669-
Below some examples:
669+
One Call objects can be thought of as datasets that "photograhp" of observed and forecasted weather data for a location: such photos are given for a specific timestamp.
670670

671-
### What is the feels like temperature (°C) tomorrow morning?
671+
It is possible to get:
672+
- current OneCall data: the "photo" given for today)
673+
- historical OneCall data: "photos" given for past days, up to 5
674+
675+
### Current OneCall data
676+
677+
#### What is the feels like temperature (°C) tomorrow morning?
672678
Always in Berlin:
673679

674680
```python
@@ -680,7 +686,7 @@ one_call = mgr.one_call(lat=52.5244, lon=13.4105)
680686
one_call.forecast_daily[0].temperature('celsius').get('feels_like_morn', None) #Ex.: 7.7
681687
```
682688

683-
### What's the wind speed in three hours?
689+
#### What's the wind speed in three hours?
684690

685691
__Attention: The first entry in forecast_hourly is the current hour.__
686692
If you send the request at 18:36 UTC then the first entry in forecast_hourly is from 18:00 UTC.
@@ -696,7 +702,7 @@ one_call = mgr.one_call(lat=52.5244, lon=13.4105)
696702
one_call.forecast_hourly[3].wind().get('speed', 0) # Eg.: 4.42
697703
```
698704

699-
### What's the current humidity?
705+
#### What's the current humidity?
700706

701707
Always in Berlin:
702708

@@ -708,3 +714,54 @@ one_call = mgr.one_call(lat=52.5244, lon=13.4105)
708714

709715
one_call.current.humidity # Eg.: 81
710716
```
717+
718+
### Historical OneCall data
719+
720+
Remember the "photograph" metaphor for OneCall data. You can query for "photos" given for past days: when you do that,
721+
be aware that such a photo carries along weather forecasts (hourly and daily) that *might* refer to the past
722+
723+
This is because - as said above - the One Call API returns hourly forecasts for a streak of 48 hours and daily forecast
724+
for a streak of 7 days, both streaks beginning from the timestamp which the OneCall object refers to
725+
726+
In case of doubt, anyway, you can always _check the reference timestamp_ for the `Weather` objects embedded into the
727+
OneCall object and check if it's in the past or not.
728+
729+
730+
#### What was the observed weather yesterday at this time?
731+
732+
Always in Berlin:
733+
734+
```python
735+
from pyowm.owm import OWM
736+
from pyowm.utils import timestamps, formatting
737+
738+
owm = OWM('your-api-key')
739+
mgr = owm.weather_manager()
740+
741+
# what is the epoch for yesterday at this time?
742+
yesterday_epoch = formatting.to_UNIXtime(timestamps.yesterday())
743+
744+
one_call_yesterday = mgr.one_call_history(lat=52.5244, lon=13.4105, dt=yesterday_epoch)
745+
746+
observed_weather = one_call_yesterday.current
747+
```
748+
749+
#### What was the weather forecasted 3 days ago for the subsequent 48 hours ?
750+
751+
No way we move from Berlin:
752+
753+
```python
754+
from pyowm.owm import OWM
755+
from pyowm.utils import timestamps
756+
from datetime import datetime, timedelta, timezone
757+
758+
owm = OWM('your-api-key')
759+
mgr = owm.weather_manager()
760+
761+
# what is the epoch for 3 days ago at this time?
762+
three_days_ago_epoch = int((datetime.now() - timedelta(days=3)).replace(tzinfo=timezone.utc).timestamp())
763+
764+
one_call_three_days_ago = mgr.one_call_history(lat=52.5244, lon=13.4105, dt=three_days_ago_epoch)
765+
766+
list_of_forecasted_weathers = one_call_three_days_ago.forecast_hourly
767+
```

0 commit comments

Comments
 (0)