If anyone is looking to add the daily weather information to their Daily Journal script (see the provided template) here is a handler that uses open source information. The point of providing this is that it does not depend on Yahoo, or Google, o news feeds or other information and, in my experience so far, is pretty reliable.
You can add this into your scripts.
(That’s your homework – you can figure it out if you try a little.)
Requirements:
Location Helper from the Mac App Store (no cost).
JSON Helper for AppleScript also from the Mac App Store (no cost).
API Key From OpenWeather – free for 1,000,000 API calls/month – be careful – don’t go wild with this
The handler
This uses getWX()
to get the data from OpenWeather and format it into a list. You can adjust the API call and JSON parsing to whatever other OpenWeather data you wish.
Click to see the AppleScript
on getWX()
-- REQUIREMENTS - tested as of 20201117
-- 1a -- Install of JSON Helper from Mac App Store
-- https://apps.apple.com/us/app/json-helper-for-applescript/id453114608?mt=12
-- 1b -- Install Location Helper from Mac App Store
-- https://apps.apple.com/us/app/location-helper/id488536386?mt=12
-- 1c -- Grant Location Helper access to location in System Preferences > Security & Privacy
-- 2 -- An API key from Open Weather
-- https://openweathermap.org/api
-- no charge for personal use as of 20201117
-- 3 -- Your location's latitude and longitude
tell application "JSON Helper"
try
(* Get my latitude and longitude*)
tell application "Location Helper"
set listCoords to get location coordinates
set _lat to item 1 of listCoords as text
set _lon to item 2 of listCoords as text
end tell
set myWXdisplay to ""
(* Get current weather from OpenWeather *)
set getWXsource to fetch JSON from ("https://api.openweathermap.org/data/2.5/weather?lat=" & _lat & "&lon=" & _lon & "&exclude=minutely,hourly&units=imperial&appid=2eb42d36ca731adc915cc0f4e694cc85")
set getWX to "High: " & temp_max of main of getWXsource & return & return & "Low: " & temp_min of main of getWXsource & return & return & "Current: " & temp of main of getWXsource & return & return & "Humidity: " & humidity of main of getWXsource & return & return & "Conditions: " & description of item 1 of weather of getWXsource
set myWXdisplay to "## Weather" & return & return & getWX & return & return
end try
return myWXdisplay
end tell
end getWX