ef-frost
ef-kassio
ef-light
+ ef-maris-dark
+ ef-maris-light
ef-night
ef-spring
ef-summer
;; read feeds list from a separate file
elfeed-feeds (esy/feeds))))
+(esy/init-step currency
+ "Track currency exchange rates."
+
+ (defvar esy/eur-to-ils-rates nil)
+
+ (add-to-list 'savehist-additional-variables
+ 'esy/eur-to-ils-rates)
+
+ (defun esy/update-eur-to-ils-rate ()
+ (require 'dom)
+ (let* ((time (float-time))
+ (from "EUR")
+ (to "ILS")
+ (amount 1)
+ (url (url-parse-make-urlobj "https"
+ nil
+ nil
+ "www.x-rates.com"
+ nil
+ (concat "/calculator/?"
+ (url-build-query-string `(("from" ,from)
+ ("to" ,to)
+ ("amount" ,amount)))))))
+ (url-retrieve url
+ (lambda (_)
+ (goto-char (point-min))
+ (search-forward "\n\n")
+ (push (cons time
+ (string-to-number (caddar (dom-by-class (libxml-parse-html-region (point))
+ "ccOutputRslt"))))
+ esy/eur-to-ils-rates))
+ nil t)))
+
+ (run-at-time t 300 #'esy/update-eur-to-ils-rate)
+
+ (defun esy/plot-eur-to-ils-rates (height width)
+ (require 'svg)
+ (let* ((svg (svg-create width height
+ :stroke "green"))
+ (time (float-time))
+ (frame (* 60 60 24))
+ (data (named-let loop ((rates esy/eur-to-ils-rates)
+ (acc nil)
+ (min most-positive-fixnum)
+ (max most-negative-fixnum))
+ (if rates
+ (let ((x (* (/ (+ frame (- (caar rates) time))
+ frame)
+ width)))
+ (if (< 0 x)
+ (let ((val (cdar rates)))
+ (loop (cdr rates)
+ (cons (cons x (cdar rates)) acc)
+ (min val min)
+ (max val max)))
+ (list acc min max)))
+ (list acc min max))))
+ (points (nth 0 data))
+ (min (nth 1 data))
+ (max (nth 2 data))
+ (normalized-points (mapcar (lambda (xy)
+ (cons (car xy)
+ (- height (* height
+ (/ (- (cdr xy) min)
+ (- max min))))))
+ points)))
+ (svg-polyline svg normalized-points :fill-color "none")
+ (svg-image svg)))
+
+ (defun esy/plot-eur-rates ()
+ (interactive)
+ (with-current-buffer-window "EUR to ILS" nil nil
+ (insert-image (esy/plot-eur-to-ils-rates 300 500))
+ (insert "\n")))
+
+ (push '(:eval (concat "1€=" (number-to-string (cdar esy/eur-to-ils-rates)) "₪ "))
+ global-mode-string))
+
(dolist (step (sort esy/init-step-times (lambda (l r) (time-less-p (cdr r) (cdr l)))))
(message "%f %s"
(float-time (cdr step))