#!/usr/bin/python3 # =================================================================== # access NWS weather forecast # =================================================================== # thanks to: https://benborgers.com/posts/weather-gov # How to use the weather.gov API # note: This is where I finally figured out how to access the # weather data # =================================================================== import requests import json lat = '34.149551' # Pasadena, CA lon = '-118.141449' # Pasadena, CA print() print('---------- JSON obj - weather at lat/lon -------------') url = f'https://api.weather.gov/points/{lat},{lon}' r = requests.get(url) j_obj = r.json() # ---- prettyprint the JSON object print(json.dumps(j_obj,indent=2)) print() print('---- high level dictionary/object keys') i = 0 for k in j_obj.keys(): i += 1 print(f'[{i:2}] {k}') print() print('---------- JSON obj - forecast at lat/lon ------------') url = j_obj['properties']['forecast'] r = requests.get(url) j_obj = r.json() # ---- prettyprint the JSON object print(json.dumps(j_obj,indent=2)) print() print('---- high level dictionary/object keys') i = 0 for k in j_obj.keys(): i += 1 print(f'[{i:2}] {k}') print()