Код: Выделить всё
{'type': 'Feature',
'geometry': {'type': 'Point', 'coordinates': [latitude, longitude, altitude]},
'properties': {'meta': {'updated_at': '2024-11-10T17:15:33Z', 'units': {'air_pressure_at_sea_level': 'hPa', 'air_temperature': 'celsius', 'cloud_area_fraction': '%', 'precipitation_amount': 'mm', 'relative_humidity': '%', 'wind_from_direction': 'degrees', 'wind_speed': 'm/s'}},
'timeseries':
[{'time': '2024-11-10T18:00:00Z', 'data': {'instant': {'details': {'air_pressure_at_sea_level': 1028.2, 'air_temperature': 12.0, 'cloud_area_fraction': 100.0, 'relative_humidity': 89.4, 'wind_from_direction': 243.8, 'wind_speed': 3.8}}, 'next_12_hours': {'summary': {'symbol_code': 'cloudy'}, 'details': {}}, 'next_1_hours': {'summary': {'symbol_code': 'cloudy'}, 'details': {'precipitation_amount': 0.0}}, 'next_6_hours': {'summary': {'symbol_code': 'cloudy'}, 'details': {'precipitation_amount': 0.1}}}}, {'time': '2024-11-10T19:00:00Z', 'data': {'instant': {'details': {'air_pressure_at_sea_level': 1028.6, 'air_temperature': 12.1,
Код: Выделить всё
#for each item in the response add the time, temp and humidity to a list
def parse_json(response):
timelist = []
for item in response['properties']['timeseries']:
utztime = {
'utztime': item['time'],
'temperature': item['data']['instant']['details']['air_temperature'],
'humidity': item['data']['instant']['details']['relative_humidity']
}
timelist.append(utztime)
return timelist
Когда я использую ответ прогноза Метеорологического бюро Великобритании, который более точен для моего местоположения, ответ выглядит следующим образом:
Все хорошо.
Когда я использую ответ прогноза Метеорологического бюро Великобритании, который более точен для моего местоположения, ответ выглядит следующим образом:
Все хорошо.
Когда я использую ответ прогноза Метеорологического бюро Великобритании, который более точен для моего местоположения, ответ выглядит следующим образом: р>
Код: Выделить всё
{"type":"FeatureCollection","features":
[{"type":"Feature",
"geometry":{"type":"Point","coordinates":[my_lat,my_long,my_alt]},
"properties":{"location":{"name":"my_local_area"},
"requestPointDistance":600.7691,
"modelRunDate":"2024-11-01T16:00Z",
"timeSeries":
[{"time":"2024-11-01T16:00Z","screenTemperature":11.85,"maxScreenAirTemp":12.27,"minScreenAirTemp":11.85,"screenDewPointTemperature":9.11,"feelsLikeTemperature":10.59,"windSpeed10m":2.98,"windDirectionFrom10m":322,"windGustSpeed10m":5.14,"max10mWindGust":6.27,"visibility":9634,"screenRelativeHumidity":82.83,"mslp":102520,"uvIndex":1,"significantWeatherCode":3,"precipitationRate":0.0,"totalPrecipAmount":0.0,"totalSnowAmount":0,"probOfPrecipitation":2},
{"time":"2024-11-01T17:00Z","screenTemperature":11.84,"maxScreenAirTemp":11.89,"minScreenAirTemp":11.83,"screenDewPointTemperature":8.85,"feelsLikeTemperature":11.37,"windSpeed10m":1.76,"windDirectionFrom10m":312,"windGustSpeed10m":3.19,"max10mWindGust":4.63,"visibility":8922,"screenRelativeHumidity":81.53,"mslp":102607,"uvIndex":0,"significantWeatherCode":8,"precipitationRate":0.0,"totalPrecipAmount":0.0,"totalSnowAmount":0,"probOfPrecipitation":9},
Код: Выделить всё
def parse_json(response):
timelist = []
for item in response['features']['properties']['timeSeries']:
utztime = {
'utztime': item['time'],
'temperature': item['data']['instant']['details']['screenTemperature'],
'humidity': item['data']['instant']['details']['screenRelativeHumidity']
}
timelist.append(utztime)
return timelist
Код: Выделить всё
for item in response['features']['properties']['timeSeries']: ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ TypeError: list indices must be integers or slices, not str
Код: Выделить всё
['features']['type']
Я сохранил ответ в переменной data, чтобы попытаться перемещаться по иерархии пар ключ:значение - ->
Код: Выделить всё
print(data['features'])
Код: Выделить всё
print(data['features']['properties']['timeSeries'])
Код: Выделить всё
print(data['features']['geometry'])
Очевидно, мне не хватает чего-то очень фундаментального, но я был бы очень признателен за некоторые рекомендации. Спасибо
Подробнее здесь: https://stackoverflow.com/questions/791 ... met-office
Мобильная версия