Created
March 17, 2011 04:05
-
-
Save miyamuko/873818 to your computer and use it in GitHub Desktop.
放射線量が 200 ミリシーベルト以上ならブブゼラを鳴らして警告。 #xyzzy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; http://doko.in/micro/ から取得した放射線量をチェックして | |
| ;; 200 ミリシーベルト以上ならブブゼラを鳴らして警告します。 | |
| ;; | |
| ;; Usage: | |
| ;; | |
| ;; 1. *radioactivity-prefecture-id* にチェックしたい県の ID を設定 | |
| ;; (デフォルトは東京の 13) | |
| ;; 2. *radioactivity-watch-interval* で監視間隔を設定 | |
| ;; (デフォルトは 1 時間) | |
| ;; 3. *radioactivity-warn-threshold* でブブゼラを鳴らす閾値を設定 | |
| ;; (デフォルトは 200 ミリシーベルト) | |
| ;; 4. M-x start-watch-radioactivity で監視開始 | |
| ;; | |
| ;; おすすめ設定: | |
| ;; | |
| ;; ;; 3 分毎にブブゼラがなるのでキッチンタイマーがわりに使えます | |
| ;; (setf *radioactivity-watch-interval* (* 3 60)) | |
| ;; (setf *radioactivity-warn-threshold* 0.001) | |
| ;; | |
| (require "vuvuzela") | |
| (require "xml-http-request") | |
| #| | |
| ((0.094 0.2 0.361 0.123 0.089 0.066 0.056 0.054 0.055 0.067 0.101 0.141 0.143 0.142 0.104 0.089)) | |
| |# | |
| (defvar *radioactivity-data* nil | |
| "http://doko.in/micro/ から取得した最新のグラフデータ") | |
| (defvar *radioactivity-prefecture-id* 13 | |
| "放射線量をチェックする県の ID。東京は 13、茨木は 8 など。 | |
| 詳細は http://doko.in/micro/ の URL や以下を参照。 | |
| http://ja.wikipedia.org/wiki/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:Map_of_the_prefectures_of_Japan_with_claimed_territories.png") | |
| (defvar *radioactivity-latest-data-index* 0 | |
| "上記データの最新データのインデックス") | |
| (defvar *radioactivity-watch-interval* (* 1 60 60) | |
| "最新データを取得する間隔(秒)。デフォルトは 1 時間。") | |
| (defvar *radioactivity-warn-threshold* (* 200 1000) | |
| "警告を出す放射能強度 (μSv/h)。デフォルトは 200 ミリシーベルト") | |
| (defvar *radioactivity-update-hook* nil | |
| "最新データを取得するたびに呼ばれるフック (引数は最新値)") | |
| (defvar *radioactivity-warn-hook* nil | |
| "*radioactivity-warn-threshold* で指定した閾値を超えると呼ばれるフック (引数は最新値)") | |
| (defun scan-radioactivity (res) | |
| (let ((html (xhr:xhr-response-text res))) | |
| (when (string-matchp "chd=t:\\(.+?\\)&" html) | |
| (let ((chd (match-string 1))) | |
| (setf *radioactivity-data* | |
| (mapcar #'(lambda (data) | |
| (mapcar #'read-from-string (split-string data #\,))) | |
| (split-string chd #\|))))))) | |
| (defun check-radioactivity (data) | |
| (let ((latest (car (last (nth *radioactivity-latest-data-index* data))))) | |
| (run-hook-with-args '*radioactivity-update-hook* latest) | |
| (when (< *radioactivity-warn-threshold* (* latest 1000 1000)) | |
| (run-hook-with-args '*radioactivity-warn-hook* latest)))) | |
| (defun watch-radioactivity () | |
| (xhr:xhr-get-async (format nil "http://doko.in/micro/?n=~A" *radioactivity-prefecture-id*) | |
| :key 'scan-radioactivity | |
| :onsuccess 'check-radioactivity | |
| :nomsg t :since :epoch | |
| )) | |
| (defun show-radioactivity (latest) | |
| (message "現在の放射線量: ~AμSv/h" latest)) | |
| (defun warn-radioactivity-by-vuvuzela (latest) | |
| (vuvuzela-play) | |
| (msgbox "現在の放射線量が警告値を超えました。~%~%現在値: ~AμSv/h~%警告値: ~AμSv/h~%~A" | |
| latest *radioactivity-warn-threshold* | |
| (format-date-string "%Y/%m/%d %H:%M:%S"))) | |
| (add-hook '*radioactivity-update-hook* 'show-radioactivity) | |
| (add-hook '*radioactivity-warn-hook* 'warn-radioactivity-by-vuvuzela) | |
| (defun start-watch-radioactivity () | |
| (interactive) | |
| (stop-watch-radioactivity) | |
| (watch-radioactivity) | |
| (start-timer *radioactivity-watch-interval* 'watch-radioactivity)) | |
| (defun stop-watch-radioactivity () | |
| (interactive) | |
| (stop-timer 'watch-radioactivity)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment