--- title: グルメサイトを横断検索した結果を anything のソースにする author: kazu634 date: 2009-11-18 wordtwit_post_info: - 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4933;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - Emacs ---
上記のスクリプトの結果を取り込んで、はてなダイアリー記法で店舗紹介テーブルを作成するソースを作成しました。
「M-x anything-gourmet」で電話番号の入力を促します。
入力された電話番号でスクリプトをキックし、出力された結果を anything のソースとします。
(defvar anything-c-source-gourmet-work "0") (defun anything_gourmet (tel) (interactive "sTelephone Number: ") (if (string-match "[0-9]+-[0-9]+-[0-9]+" tel) (progn (setq anything-c-source-gourmet-work tel) (anything 'anything-c-source-gourmet nil "Title: " nil nil anything-call-source-buffer)) (message "Please enter Telephone Number!"))) (defvar anything-c-source-gourmet '((name . "Cross-Gourmet Site Search") (candidates . (lambda () (delete "" (split-string (shell-command-to-string (format "gourmet %s" anything-c-source-gourmet-work)) "\n")))) (candidate-transformer . (lambda (candidates) (mapcar (function (lambda(arg) (let* ((str_list (split-string arg "\t")) (site (nth 0 str_list)) (shopname (nth 1 str_list))) (cons (format "[%s] %s" site shopname) arg)))) candidates))) (action . (("Insert" . insert_gourmet))) (migemo))) (defun insert_gourmet (candidate) (let* ((str-list (split-string candidate "\t")) (site (nth str-list)) (shopname (nth 1 str-list)) (address (nth 2 str-list)) (url (nth 3 str-list)) (tel (nth 4 str-list))) (insert (format "|*店名|[%s:title=%s]|\n" url shopname)) (insert (format "|*住所|%s|\n" address)) (insert (format "|*電話番号|%s|\n" tel))))