File: postcodes_to_lat_lng.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 (26 lines) | stat: -rw-r--r-- 790 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
#!/usr/bin/env python
"""
A variation on current_weather.py which uses postcodes rather than lon lat.
"""

import postcodes_io_api

import datapoint

# Create datapoint connection
manager = datapoint.Manager(api_key="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")


# Get longitude and latitude from postcode
postcodes_conn = postcodes_io_api.Api()
postcode = postcodes_conn.get_postcode("SW1A 2AA")
latitude = postcode["result"]["latitude"]
longitude = postcode["result"]["longitude"]

# Get a forecast for the nearest site
forecast = manager.get_forecast(longitude, latitude, "hourly")

# Get the current timestep using now() and print out some info
now = forecast.now()
print(now["significantWeatherCode"])
print(f"{now['screenTemperature']['value']} {now['screenTemperature']['unit_symbol']}")