February 2, 2019

Inserting the current weather into an Emacs buffer

I’m trying to learn a little elisp. It’s slow going, so having a specific need is helpful.

I like to insert the current weather in each day’s org-journal entry. Previously, I had a TextExpander snippet that would insert the following:

#+BEGIN_SRC sh :results value verbatim
curl "wttr.in/49301?0pQT"
#+END_SRC

This works, but I have to activate the snippet, put the point on the #+BEGIN_SRC line, hit C-c C-c to run it, then delete the block.

As an elisp-learning exercise I thought I’d try creating a function that would do everything for me. Here’s what I came up with:

(defun jab-insert-weather ()
  (interactive)
  (let ((w (shell-command-to-string "curl -s 'wttr.in/49301?0pQT'")))
  (insert (mapconcat (function (lambda (x) (format ": %s" x)))
           (split-string w "\n")
           "\n"))

Now, typing M-x jab-insert-weather will insert something like the following into the current buffer:

:               Overcast 
:      .--.     14-21 °F
:   .-(    ).   ↗ 8-20 mph 
:  (___.__)__)  12 mi
:               0.0 in | 0%

emacs


Previous post
In Baltimore, the future of film culture is an old-school video store The Outline: You cannot trust the internet to keep media available, and you cannot trust corporations to commit to supporting film culture. I
Next post
All Systems Red (The Murderbot Diaries #1) All Systems Red by Martha Wells My rating: 4 of 5 stars This was a ton of fun. A nice combination of action, characters, and humor.