From 36eccc1af1c85a01511d239f03626ea8be86e2dd Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Sun, 24 Jul 2022 23:30:41 +0300 Subject: [PATCH] feat(emacs): add weather from wttr.in to org-journal --- .emacs.d/init.el | 29 +++++++++++++++++++++++++++-- Emacs.org | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index ab8789c..e45fbbf 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -2939,12 +2939,37 @@ Returns ( . ) or nil." :keymaps 'org-journal-mode-map "C-c t" #'org-journal-tags-insert-tag)) +(use-package request + :straight t + :defer t) + +(defvar my/weather-last-time nil) +(defvar my/weather-value nil) + +(defun my/weather-get () + (when (> (- (time-convert nil 'integer) my/weather-last-time) + (* 60 5)) + (request (format "https://wttr.in/%s" my/location) + :params '(("format" . "%l:%20%C%20%t%20%w%20%p")) + :sync t + :parser (lambda () (url-unhex-string (buffer-string))) + :success (cl-function + (lambda (&key data &allow-other-keys) + (setq my/weather-value data) + (setq my/weather-last-time (time-convert nil 'integer)))) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))))) + my/weather-value) + (defun my/set-journal-header () (org-set-property "Emacs" emacs-version) (org-set-property "Hostname" system-name) (org-journal-tags-prop-apply-delta :add (list (format "host.%s" (system-name)))) (when (boundp 'my/location) - (org-set-property "Location" my/location)) + (org-set-property "Location" my/location) + (when-let ((weather (my/weather-get))) + (org-set-property "Weather" weather))) (when (boundp 'my/loc-tag) (org-journal-tags-prop-apply-delta :add (list my/loc-tag))) (when (fboundp 'emms-playlist-current-selected-track) @@ -3925,7 +3950,7 @@ With ARG, repeats or can move backward if negative." (aweshell-alert-command-face :foreground (doom-color 'red) :weight 'bold)) :config (setq eshell-prompt-regexp "^[^#\nλ]* λ[#]* ") - (setq eshell-highlight-prompt nil) + (setq eshell-highlight-prompt t) (setq eshell-prompt-function 'epe-theme-pipeline)) (use-package eshell-info-banner diff --git a/Emacs.org b/Emacs.org index ab9f74c..c04445f 100644 --- a/Emacs.org +++ b/Emacs.org @@ -4124,16 +4124,48 @@ I've tried switching to Org Roam Dailies, but in the end decided that org-journa "C-c t" #'org-journal-tags-insert-tag)) #+end_src -I also want to store some information in the journal as properties of the record. So below is a function that does just that. +Also, I want to add some extra information to the journal. Here's a functionality to get the current weather from wttr.in: +#+begin_src emacs-lisp +(use-package request + :straight t + :defer t) + +(defvar my/weather-last-time nil) +(defvar my/weather-value nil) + +(defun my/weather-get () + (when (> (- (time-convert nil 'integer) my/weather-last-time) + (* 60 5)) + (request (format "https://wttr.in/%s" my/location) + :params '(("format" . "%l:%20%C%20%t%20%w%20%p")) + :sync t + :parser (lambda () (url-unhex-string (buffer-string))) + :success (cl-function + (lambda (&key data &allow-other-keys) + (setq my/weather-value data) + (setq my/weather-last-time (time-convert nil 'integer)))) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))))) + my/weather-value) +#+end_src + +And here's a function that creates a drawer with such information. At the moment, it's: +- Emacs version +- Hostname +- Location +- Weather +- Current EMMS track -As of now, it stores Emacs version, hostname, location, and current EMMS track if there is one. #+begin_src emacs-lisp (defun my/set-journal-header () (org-set-property "Emacs" emacs-version) (org-set-property "Hostname" system-name) (org-journal-tags-prop-apply-delta :add (list (format "host.%s" (system-name)))) (when (boundp 'my/location) - (org-set-property "Location" my/location)) + (org-set-property "Location" my/location) + (when-let ((weather (my/weather-get))) + (org-set-property "Weather" weather))) (when (boundp 'my/loc-tag) (org-journal-tags-prop-apply-delta :add (list my/loc-tag))) (when (fboundp 'emms-playlist-current-selected-track)