Skip to content

Instantly share code, notes, and snippets.

@syohex
Last active November 9, 2016 03:49
Show Gist options
  • Select an option

  • Save syohex/dc1f20d439a1cc71cdfa59dcc7d8e0b4 to your computer and use it in GitHub Desktop.

Select an option

Save syohex/dc1f20d439a1cc71cdfa59dcc7d8e0b4 to your computer and use it in GitHub Desktop.
;;; usa-president-2016.el --- Show USA president 2016 election -*- lexical-binding: t; -*-
;; Copyright (C) 2016 by Syohei YOSHIDA
;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL: https://github.com/syohex/
;; Version: 0.01
;; Package-Requires: ((emacs "24"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'url)
(require 'json)
(defun usa-president-2016 ()
(interactive)
(let ((curbuf (current-buffer)))
(url-retrieve
"http://elections.huffingtonpost.com/2016/results/president.json"
(lambda (status &rest args)
(goto-char url-http-end-of-headers)
(let* ((res (json-read-from-string (buffer-substring (point) (point-max))))
(summaries (assoc-default 'summaries res))
(president (assoc-default 'president summaries)))
(with-current-buffer curbuf
(setq-default header-line-format
(format "Clinton(%d) vs Trump(%d)"
(assoc-default 'nClintonElectoralVotes president)
(assoc-default 'nTrumpElectoralVotes president))))
(run-with-idle-timer 60 nil #'usa-president-2016)))
nil t)))
(provide 'usa-president-2016)
;;; usa-president-2016.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment