File: simple_forecast.py

package info (click to toggle)
python-datapoint 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 584 kB
  • sloc: python: 3,062; makefile: 18
file content (30 lines) | stat: -rwxr-xr-x 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
This example will print out a simple forecast for the next 5 days.
It will allow us to explore the day, timestep and element objects.
"""

import datetime

import datapoint

# Create datapoint connection
manager = datapoint.Manager(api_key="api key goes here")


forecast = manager.get_forecast(51.500728, -0.124626, frequency="hourly")

# Loop through timesteps and print information
for timestep in forecast.timesteps:
    print(timestep["time"])
    print(timestep["significantWeatherCode"]["value"])
    print(
        "{temp} {temp_units}".format(
            temp=timestep["screenTemperature"]["value"],
            temp_units=timestep["screenTemperature"]["unit_symbol"],
        )
    )

print(forecast.now())

print(forecast.at_datetime(datetime.datetime(2024, 2, 11, 14, 0)))