捨てコード

人狼の桃栗鯖では過去ログを一定数以上残さないので、ログを保存しようと思って適当にコードを書いてみた。プレイ記録としてサーバ名と番地をメモしていたのだが、過去ログがHTML化するのに時間がかかるので、今まで拾っていなかったのだ。手作業で拾うのはあまりにも面倒なので、当然自動化する。こういうときにスクリプトが書けると便利だ。

(defun wget-open (txt dir)
  (call-process (concat "wget -i " txt)
                :exec-directory dir))
(defun extract-jinro-log (l-file a-file b-file)
  (find-file l-file)
  (set-buffer (get-file-buffer l-file))
  (goto-char 0)
  (with-open-file (a-fp a-file :direction :output
                        :if-exists :overwrite
                        :if-does-not-exist :create)
    (with-open-file (b-fp b-file :direction :output
                          :if-exists :overwrite
                          :if-does-not-exist :create)
      (while (scan-buffer "\\(続\\|桃栗\\)\\([0-9]\\{5\\}\\)" :tail t :regexp t)
        (if (string= (match-string 1) "続")
            (format a-fp "http://jinrou.dip.jp/~~jinrou/kako/~A.html~%"
                    (match-string 2))
          (format b-fp "http://www7a.biglobe.ne.jp/~~kuri/kako/~A.html~%"
                  (match-string 2)))))))
(defun wget-jinro-log (a-dir b-dir)
  (let ((l-file (merge-pathnames "jinro.txt" (si:system-root)))
        (a-file (merge-pathnames "zoku.txt" (si:system-root)))
        (b-file (merge-pathnames "momo.txt" (si:system-root))))
    (extract-jinro-log l-file a-file b-file)
    (wget-open a-file a-dir)
    (wget-open b-file b-dir)))

30分くらいで適当に書いたので非常に効率的でない。パッと能率的に書ければ良いのだが、現時点での指標として。面倒なので特にコメントなし。