- #!/usr/bin/python3
-
- import requests
- import textwrap
-
- # Docs:
- # - https://www.weather.gov/documentation/services-web-api
- # - https://weather-gov.github.io/api/general-faqs
-
- # markers for vimwiki:
- print('[[/lyons-colorado]] [[/weather]]')
- print()
- print('{{{')
-
- # This address is geocoded from the forecast property in
- # https://api.weather.gov/points/40.226,-105.2713
- # r = requests.get('https://api.weather.gov/gridpoints/BOU/55,84/forecast/hourly')
- r = requests.get('https://api.weather.gov/gridpoints/BOU/55,84/forecast')
- data = r.json()
-
- # Pull out forecast periods from API
- for period in data['properties']['periods']:
- precip = period['probabilityOfPrecipitation']['value']
- if not precip:
- precip = ''
- else:
- precip = ", {0}% chance precip".format(precip)
-
- if not period['name']:
- prefix = period['startTime']
- else:
- prefix = period['name']
-
- print('{0}: {1[temperature]}°{1[temperatureUnit]}, wind {1[windSpeed]} {1[windDirection]}{2}\n [{1[shortForecast]}]'.format(prefix, period, precip))
-
- if period['detailedForecast']:
- print(textwrap.fill(period['detailedForecast'], width=70, initial_indent=' ', subsequent_indent=' ') + "\n")
-
- print('}}}')
|