From 6c3212c7362245a329cbf16bafabb7f4a1f9f3de Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Tue, 31 May 2022 19:28:54 -0700 Subject: feat(cheeseboard): module to get the list of pizzas from cheeseboard To see which pizzas are available this week at cheeseboard within Emacs is a dream come true. What's better than "M-x my/cheeseboard-menu" ?! This displays in a buffer the list of pizzas for the week. It includes the ingredients for the pizza, and hours of operation for that day (since the hours depending on the day of the week). --- emacs/elisp/my-cheeseboard.el | 55 +++++++++++++++++++++++++++++++++++++++++++ emacs/init.el | 1 + 2 files changed, 56 insertions(+) create mode 100644 emacs/elisp/my-cheeseboard.el diff --git a/emacs/elisp/my-cheeseboard.el b/emacs/elisp/my-cheeseboard.el new file mode 100644 index 0000000..9713e14 --- /dev/null +++ b/emacs/elisp/my-cheeseboard.el @@ -0,0 +1,55 @@ +;;; my-cheeseboard.el --- summary -*- lexical-binding: t -*- +;; Author: Franck Cuny + +;;; Commentary: + +;; commentary: +;; As everybody knows, the best pizza in the world is at +;; cheeseboard[0]. I like to check during the week the pizzas for the +;; week and see if there are any we would like to have. This module +;; gets the list of pizzas for the week and display them in a buffer. +;; +;; [0] https://cheeseboardcollective.coop/ + +;;; Code: + +(require 'dom) + +(defconst my/cheeseboard-buffer "*cheeseboard-menu*" + "Name of the buffer for displaying the week's menu.") + +(defconst my/cheeseboard-url "https://cheeseboardcollective.coop/pizza/" + "URL to fetch to get the list of pizzas for the week.") + +(defun my/cheeseboard-menu () + "Display the list of pizzas for the week." + (interactive) + (let* ((dom (with-current-buffer (url-retrieve-synchronously my/cheeseboard-url) + (libxml-parse-html-region (point-min) (point-max)))) + ;; a class named `pizza-list' contains all the items for the + ;; week. they are wrapped in a `article' tag. + (menus (dom-by-tag (dom-by-class dom "pizza-list") 'article)) + (inhibit-read-only t) + (buffer-undo-list t)) + (pop-to-buffer my/cheeseboard-buffer) + (erase-buffer) + (insert (format "if you want to look at the menu on the website => %s\n\n" my/cheeseboard-url)) + (dolist (menu menus) + (my/pizza-of-the-day menu)) + (special-mode))) + +(defun my/pizza-of-the-day (menu) + "Print the pizzas for the day from the MENU." + (let* ((date (car (dom-strings (dom-by-tag (dom-by-class menu "date") 'p)))) + (pizza (dom-by-tag (dom-by-class menu "menu") 'p))) + (if (string= "The pizzeria is closed today." (nth 0 (dom-strings pizza))) + (insert (format "%s: cheeseboard is closed :(\n\n" (propertize date 'face 'italic))) + (insert (format "%s: 🍕 %s\n(note: %s, %s)\n\n" + (propertize date 'face 'italic) + (propertize (replace-regexp-in-string "\n" "" (nth 2 (dom-strings pizza))) 'face 'highlight) + (nth 0 (dom-strings pizza)) + (nth 1 (dom-strings pizza))))))) + +(provide 'my-cheeseboard) + +;;; my-cheeseboard.el ends here diff --git a/emacs/init.el b/emacs/init.el index 399aab1..5256c39 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -101,6 +101,7 @@ Missing packages are installed automatically." (require 'my-web) (require 'my-work) (require 'my-uptime) +(require 'my-cheeseboard) (require 'my-packages-extra) ;;; init.el ends here -- cgit 1.4.1