Estoy tratando de obtener uno datos de la pagina Wunderground "https://www.wunderground.com/dashboard/pws/KNYNEWYO1614/table/2023-04-30/2023-04-30/daily
" Pero cuando leo el HTML mis tablas salen vacias con solo los encabezados. So estoy tratando de leer los datos usando un endpoint API ahora mi problema surge cuando trato de anadir fecha al endpoint. Aqui podemos ver que el endpoint funciona para sacar datos del dia actual pero cuando anado las fechas me da un error.
endpoint = "https://api.weather.com/v2/pws/observations/current?apiKey=e1f10a1e78da46f5b10a1e78da96f525&stationId=KNYNEWYO1585&numericPrecision=decimal&format=json&units=e"
response = requests.get(endpoint).json()
print(response)
Aqui esta el ejemplo anadiendo fechas.
from datetime import datetime
import requests
from tabulate import tabulate
apiKey = "e1f10a1e78da46f5b10a1e78da96f525"
station_id = "KNYNEWYO1585"
start_date = "2023-04-30"
end_date = "2023-04-30"
endpoint = f"https://api.weather.com/v2/pws/observations/historical.json?apiKey={apiKey}&stationId={station_id}&format=json&units=e&date={start_date}&endDate={end_date}"
response = requests.get(endpoint).json()["observations"]
weather_data = sorted(response, key=lambda k: k["epoch"])
header = [
"Time", "Temperature", "Dew Point", "Humidity", "Wind",
"Wind Speed", "Wind Gust", "Pressure", "Precip.", "Conditions",
]
table = []
for item in weather_data:
row = [
datetime.fromtimestamp(item["epoch"]).strftime('%I:%M %p'),
item["temp"],
f'{item["dewpt"]} °F',
f'{item["humidity"]} %',
item["winddir"],
item["wspd"],
f'{item["wgust"] if "wgust" in item else 0} mph',
f'{item["pressure"]} in',
f'{item["precip_total"] if "precip_total" in item else "0.0 in"}',
item["wx_phrase"],
]
table.append(row)
print(tabulate(table, headers=header, tablefmt="pretty"))
Este es el error que me da
JSONDecodeError Traceback (most recent call last)
<ipython-input-10-873917b622c8> in <module>
10 endpoint = f"https://api.weather.com/v2/pws/observations/historical.json?apiKey={apiKey}&stationId={station_id}&format=json&units=e&date={start_date}&endDate={end_date}"
11
---> 12 response = requests.get(endpoint).json()["observations"]
13 weather_data = sorted(response, key=lambda k: k["epoch"])