update to use the new IBM observations API
This commit is contained in:
parent
7e183d48b3
commit
9bce9e8128
1 changed files with 54 additions and 36 deletions
|
@ -194,56 +194,74 @@ def geocode(latitude, longitude):
|
||||||
|
|
||||||
old_style_fcstdaily7 = { 'forecasts': new_ibm_to_old_ibm(language, units, forecast) }
|
old_style_fcstdaily7 = { 'forecasts': new_ibm_to_old_ibm(language, units, forecast) }
|
||||||
|
|
||||||
current_req = requests.get(f"{ibm_root}/v1/geocode/{latitude}/{longitude}/observations.json?language={language}&units={units}&apiKey={ibm_key}")
|
current_req = requests.get(f"{ibm_root}/v3/wx/observations/current?geocode={latitude},{longitude}&language={language}&units={units}&format=json&apiKey={ibm_key}")
|
||||||
current_req.raise_for_status()
|
current_req.raise_for_status()
|
||||||
current = current_req.json()
|
current = current_req.json()
|
||||||
observation = current['observation']
|
|
||||||
|
|
||||||
old_style_conditions = {
|
old_style_conditions = {
|
||||||
'metadata': current['metadata'],
|
'metadata': {
|
||||||
|
'language': language,
|
||||||
|
'transaction_id': 'lol!',
|
||||||
|
'version': '1',
|
||||||
|
'latitude': latitude,
|
||||||
|
'longitude': longitude,
|
||||||
|
'units': units,
|
||||||
|
'expire_time_gmt': current['expirationTimeUtc'],
|
||||||
|
'status_code': 200,
|
||||||
|
},
|
||||||
'observation': {
|
'observation': {
|
||||||
'class': observation['class'],
|
'class': 'observation',
|
||||||
'expire_time_gmt': observation['expire_time_gmt'],
|
'expire_time_gmt': current['expirationTimeUtc'],
|
||||||
'obs_time': observation['valid_time_gmt'],
|
'obs_time': current['validTimeUtc'],
|
||||||
# 'obs_time_local': we don't know.
|
# 'obs_time_local': we don't know.
|
||||||
'wdir': observation['wdir'],
|
'wdir': current['windDirection'],
|
||||||
'icon_code': observation['wx_icon'],
|
'icon_code': current['iconCode'],
|
||||||
'icon_extd': observation['icon_extd'],
|
'icon_extd': current['iconCodeExtend'],
|
||||||
# sunrise: we don't know these, but we could yank them out of the forecast for today.
|
# sunrise: we don't know these, but we could yank them out of the forecast for today.
|
||||||
# sunset
|
# sunset
|
||||||
'day_ind': observation['day_ind'],
|
'day_ind': current['dayOrNight'],
|
||||||
'uv_index': observation['uv_index'],
|
'uv_index': current['uvIndex'],
|
||||||
# uv_warning: I don't even know what this is. Apparently numeric.
|
# uv_warning: I don't even know what this is. Apparently numeric.
|
||||||
# wxman: ???
|
# wxman: ???
|
||||||
'obs_qualifier_code': observation['qualifier'],
|
'obs_qualifier_code': current['obsQualifierCode'],
|
||||||
'ptend_code': observation['pressure_tend'],
|
'ptend_code': current['pressureTendencyCode'],
|
||||||
'dow': datetime.datetime.utcfromtimestamp(observation['valid_time_gmt']).strftime('%A'),
|
'dow': current['dayOfWeek'],
|
||||||
'wdir_cardinal': observation['wdir_cardinal'], # sometimes this is "CALM", don't know if that's okay
|
'wdir_cardinal': current['windDirectionCardinal'], # sometimes this is "CALM", don't know if that's okay
|
||||||
'uv_desc': observation['uv_desc'],
|
'uv_desc': current['uvDescription'],
|
||||||
# I'm just guessing at how the three phrases map.
|
# I'm just guessing at how the three phrases map.
|
||||||
'phrase_12char': observation['blunt_phrase'] or observation['wx_phrase'],
|
'phrase_12char': current['wxPhraseShort'],
|
||||||
'phrase_22char': observation['terse_phrase'] or observation['wx_phrase'],
|
'phrase_22char': current['wxPhraseMedium'],
|
||||||
'phrase_32char': observation['wx_phrase'],
|
'phrase_32char': current['wxPhraseLong'],
|
||||||
'ptend_desc': observation['pressure_desc'],
|
'ptend_desc': current['pressureTendencyTrend'],
|
||||||
# sky_cover: we don't seem to get a description of this?
|
# sky_cover: we don't seem to get a description of this?
|
||||||
'clds': observation['clds'],
|
'clds': current['cloudCoverPhrase'], # old was 'CLR', new is 'Partly Cloudy'
|
||||||
'obs_qualifier_severity': observation['qualifier_svrty'],
|
'obs_qualifier_severity': current['obsQualifierSeverity'],
|
||||||
# vocal_key: we don't get one of these
|
# vocal_key: we don't get one of these
|
||||||
{'e': 'imperial', 'm': 'metric', 'h': 'uk_hybrid'}[units]: {
|
{'e': 'imperial', 'm': 'metric', 'h': 'uk_hybrid'}[units]: {
|
||||||
'wspd': observation['wspd'],
|
'wspd': current['windSpeed'],
|
||||||
'gust': observation['gust'],
|
'gust': current['windGust'],
|
||||||
'vis': observation['vis'],
|
'vis': current['visibility'],
|
||||||
# mslp: don't know what this is but it doesn't map to anything
|
'mslp': current['pressureMeanSeaLevel'],
|
||||||
'altimeter': observation['pressure'],
|
'altimeter': current['pressureAltimeter'],
|
||||||
'temp': observation['temp'],
|
'temp': current['temperature'],
|
||||||
'dewpt': observation['dewPt'],
|
'dewpt': current['temperatureDewPoint'],
|
||||||
'rh': observation['rh'],
|
'rh': current['relativeHumidity'],
|
||||||
'wc': observation['wc'],
|
'wc': current['temperatureWindChill'],
|
||||||
'hi': observation['heat_index'],
|
'hi': current['temperatureHeatIndex'],
|
||||||
'feels_like': observation['feels_like'],
|
'feels_like': current['temperatureFeelsLike'],
|
||||||
# temp_change_24hour, temp_max_24hour, temp_min_24hour, pchange: don't get any of these
|
'temp_change_24hour': current['temperatureChange24Hour'],
|
||||||
# {snow,precip}_{{1,6,24}hour,mtd,season,{2,3,7}day}: don't get these either
|
'temp_max_24hour': current['temperatureMax24Hour'],
|
||||||
# ceiling, obs_qualifier_{100,50,32}char: or these.
|
'temp_min_24hour': current['temperatureMin24Hour'],
|
||||||
|
'pchange': current['pressureChange'],
|
||||||
|
'snow_1hour': current['snow1Hour'],
|
||||||
|
'snow_6hour': current['snow6Hour'],
|
||||||
|
'snow_24hour': current['snow24Hour'],
|
||||||
|
'precip_1hour': current['precip1Hour'],
|
||||||
|
'precip_6hour': current['precip6Hour'],
|
||||||
|
'precip_24hour': current['precip24Hour'],
|
||||||
|
# {snow,precip}_{mtd,season,{2,3,7}day}: don't get these either
|
||||||
|
'ceiling': current['cloudCeiling'],
|
||||||
|
# obs_qualifier_{100,50,32}char: or these.
|
||||||
# these are all now in their own request that you can pay extra to retrieve.
|
# these are all now in their own request that you can pay extra to retrieve.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue