The weather in your emacs journals
Obviously I like journelly and so went on a dive into getting the weather into my other notes and across platforms eventually stumbling upon wttr.in
From the github site: https://github.com/chubin/wttr.in wttr.in is a console-oriented weather forecast service that supports various information representation methods like terminal-oriented ANSI-sequences for console HTTP clients (curl, httpie, or wget), HTML for web browsers, or PNG for graphical viewers.
I've had a few calls to it that have failed, but most of the time it reports back beautifully. So how do we get the weather from wttr into an orgmode file?
On MS Windows I use this snippet
'# -*- mode: snippet -*-
'# name: Weather today (wttr.in, prompt city)
'# key: dl
'# --
* `(format-time-string "%Y-%m-%d %a %H:%M")` $1
:PROPERTIES:
:WEEK: `(format-time-string "WK%V")`
:WEATHER: `(let* ((place (read-string "City: " wttr-weather-default-location))
(raw (with-temp-buffer
(call-process
"C:/Windows/system32/curl.exe" nil '(t t) nil
"-s"
(format "wttr.in/%s?format=4"
(replace-regexp-in-string " " "+" place)))
(string-trim (buffer-string)))))
raw)`
:MILEAGE:
:START:
:FINISH:
:END:
and the above returns the weather in this format;
London: ☁️ 🌡️+8°C 🌬️↖8km/h
although you can also use it in your init.el as a function
(defun my/get-weather (city) "Fetch weather from wttr.in and remove the city prefix." (let* ((raw (shell-command-to-string (format "curl -A curl -s --max-time 5 \"https://wttr.in/%s?format=3\"" city))) (clean (string-trim raw))) ;; Remove leading 'City: ' if present (if (string-match "^[^:]+: \\(.*\\)$" clean) (match-string 1 clean) clean)))
my/get-weather
You can tweak the format but as written above format=3 returns something like this;
Silao: ☀️ +29°C
So happy weather recording!