aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/yr.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/yr.py')
-rw-r--r--scripts/yr.py42
1 files changed, 25 insertions, 17 deletions
diff --git a/scripts/yr.py b/scripts/yr.py
index 6d53d5c..d4dc159 100644
--- a/scripts/yr.py
+++ b/scripts/yr.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-''' Get weatherdata from yr.no '''
+""" Get weatherdata from yr.no """
import os
import sys
@@ -7,11 +7,16 @@ import sys
import common
import requests
-location = int(os.environ['el_location'])
-lat = str(os.environ['el_yr_lat'])
-lon = str(os.environ['el_yr_lon'])
+location = int(os.environ["el_location"])
+lat = str(os.environ["el_yr_lat"])
+lon = str(os.environ["el_yr_lon"])
-apiUrl = "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=" + lat + "&lon=" + lon
+apiUrl = (
+ "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat="
+ + lat
+ + "&lon="
+ + lon
+)
### Get the data
try:
@@ -19,8 +24,8 @@ try:
# Request headers
hdr = {
- 'User-Agent': 'gratis.morell@litepost.no',
- 'Cache-Control': 'no-cache',
+ "User-Agent": "gratis.morell@litepost.no",
+ "Cache-Control": "no-cache",
}
response = requests.get(url, headers=hdr, timeout=10)
@@ -41,18 +46,21 @@ data = response.json()
values = []
for item in data["properties"]["timeseries"]:
details = item["data"]["instant"]["details"]
- values.append((
- item["time"],
- location,
- details["air_temperature"],
- details["air_pressure_at_sea_level"],
- details["cloud_area_fraction"],
- details["relative_humidity"],
- details["wind_from_direction"],
- details["wind_speed"]))
+ values.append(
+ (
+ item["time"],
+ location,
+ details["air_temperature"],
+ details["air_pressure_at_sea_level"],
+ details["cloud_area_fraction"],
+ details["relative_humidity"],
+ details["wind_from_direction"],
+ details["wind_speed"],
+ )
+ )
# SQL
-sql = """INSERT INTO yr (
+sql = """INSERT INTO yr (
time,
location,
air_temperature,