Skip to content

Instantly share code, notes, and snippets.

@ClaireSoftware
Last active October 7, 2019 21:26
Show Gist options
  • Save ClaireSoftware/0c55c4d5dbbe7a8ba57a29c391d13c91 to your computer and use it in GitHub Desktop.
Save ClaireSoftware/0c55c4d5dbbe7a8ba57a29c391d13c91 to your computer and use it in GitHub Desktop.
script to get menu of schiletter dining hall
#!/bin/sh
":"; exec emacs --quick --script "$0" "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
(defun schiletter-menu ()
(interactive)
(require 'dom)
(require 'cl)
;; url seems to have "period ID" for meals
;; breakfast is 891
;; lunch is 892
;; 893 is dinner
;; brunch is 973
;; "All day" is 3000
(let* ((document (shell-command-to-string "curl -s https://clemson.campusdish.com/LocationsAndMenus/SchilletterDiningHall"))
(campusdish (with-temp-buffer
(insert document) (libxml-parse-html-region
(point-min) (point-max) nil t)))
(item-names (dom-by-class campusdish "menu__station"))
(station-names (dom-by-class campusdish "section-subtitle"))
(names)
(snames))
;; cadr is important here,
;; it selects which station to get the items of, in this case 2nd, deli
(let ((counter 0))
(while (> (length item-names) counter)
(let ((lnames (dom-by-class (nth counter item-names) "viewItem"))
(lstrings))
(dolist (n lnames) (push (dom-text n) lstrings))
(push (reverse lstrings) names))
(incf counter)))
(dolist (n station-names) (push (dom-text n) snames))
(setq names (reverse names))
(setq snames (reverse snames))
(if noninteractive
(progn
(princ (format "\n%s\nToday's schilleter menu :)" (format-time-string "%a. %b %y")))
(map 'nil
(lambda (sname names) (princ (format "\n\n* %s\n" sname))
(mapc (lambda (name) (princ (format "** %s\n" name))) names)) snames names ))
(with-current-buffer (get-buffer-create "menu")
(erase-buffer)
(org-mode)
(map 'nil
(lambda (sname names) (insert "\n\n* ") (insert sname) (insert "\n")
(mapc (lambda (name) (insert "\n** ") (insert name)) names)) snames names )))))
(if noninteractive (schiletter-menu))
(provide 'dininghall)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment