check-url-update.el

Submitted by reeses on Sun, 2006-03-26 21:51. |

This is an elisp script that will sort-of duplicate the functionality of sites such as http://www.changedetect.com, which suck. Don't use them. Use this script, and when you get sick of it in twenty minutes, write a real program, with real threading, and a real UI, and then give me a copy. Yes, I can hear you OmniWeb types laughing at the rest of us pathetic souls. Tested on XEmacs 21.4.

Addendum: It was suggested to me by one of the employees of the aforementioned service that I was off on a "mindless rant" regarding their suction, and was asked to give evidence. I went to the site to start a list, and was greeted with a MSSQL server error. I don't think I need to continue. :-)

Addendum 2: Thankfully, RSS is appearing everywhere, and external sites such as these will become obsolete very soon.

Other options:

zwebwatch Dashboard Widget

;; I was annoyed at http://www.ChangeDetect.com, so I wrote this.  Use
;; this script, and when you get sick of it in twenty minutes, write a
;; real program, with real threading, and a real UI, and then give me
;; a copy.  Tested on XEmacs 21.4.
;; Usage: UTSL.  Hackery needed.
;; (c) 2003 Art Taylor 

(require 'url)
(require 'md5)

(setq output-buffer-name "*url-updates*")

(defun get-new-hash (url)
  "Hash the page found at the given url."
  (md5 (let ((url-multiple-p nil))
	 (save-excursion
	   (save-window-excursion
	     (url-retrieve url)))
	 (buffer-string url-working-buffer))))

(defun save-url-alist ()
  "Save my-url-alist to the file."
  (with-temp-buffer 
    (insert "(setf my-url-alist '" )
    (prin1 my-url-alist (current-buffer))
    (insert ") ")
    (write-region (point-min) (point-max) (expand-file-name "~/.check-url.el"))))

(defun check-url-for-update (x)
  "Check the page at the url in the car of the cons cell for 
   an update, comparing its hash to that in the cdr."
  (let ((url (car x))
	(oldhash (cdr x))
	(newhash (get-new-hash (car x))))
    (if (not (string= oldhash newhash))
	(progn
	  (princ (concat (current-time-string) ":" url "\n") (get-buffer-create output-buffer-name))
	  (setf (cdr x) newhash)))))

(defun check-updates ()
  "Check all of the urls in my-url-alist for updates."
  (load-file (expand-file-name "~/.check-url.el"))
  (mapcar #'check-url-for-update my-url-alist)
  (save-url-alist))

(defun add-url (url)
  "Add the given url to my-url-alist and save to file."
  (if (not (assoc url my-url-alist))
      (progn 
	(setf my-url-alist (cons `(,url . "1") my-url-alist))
	(save-url-alist))))

(load-file (expand-file-name "~/.check-url.el"))

(add-url "http://lambda.weblogs.com")
(add-url "http://www.astrogoth.com/~reeses/musing/index.html")
(add-url "http://www.slashdot.org")

(check-updates)

Post new comment

Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.