Javelin:

(import java.util)

(def interval 5)
(prn "Refreshes every" interval "minutes.")

;; compile-time regex
(defmacro regex (str)
  (. java.util.regex.Pattern compile str))

(defn re-groups (re text g)
  (def result (list))
  (def m (. re matcher text))
  (while (. m find) (. result add (. m group g)))
  result)

(defn list-naver ()
  (re-groups (regex "<option value=\".+\">.+: (.+)</option>") (slurp "http://www.naver.com") 1))

(defn list-daum ()
  (new LinkedHashSet
    (re-groups
      (regex "<span class=\"txt_issue\">\n.+\n(<.+>)?(.+?)(<.+>)?\n") (slurp "http://www.daum.net") 2)))

(while true
  (try
    (prn (new Date))       
    (prn "Naver:" (list-naver))
    (prn "Daum:" (list-daum))
    (catch Exception e (prn e)))
  (. Thread sleep (* 1000 60 interval))
  (prn))

 

Clojure:

(import (java.util Date))
 
(def interval 5)
(println "Refreshes every" interval "minutes.")

(defn list-naver []
  (map #(% 1) (re-seq #"<option value=\".+\">.+: (.+)</option>" (slurp "http://www.naver.com"))))

(defn list-daum []
  (distinct (map #(% 2) (re-seq #"<span class=\"txt_issue\">\n.+\n(<.+>)?(.+?)(<.+>)?\n" (slurp "http://www.daum.net")))))

(while true
  (try
    (println (str (new Date)))
    (println "Naver:" (clojure.string/join ", " (list-naver)))
    (println "Daum:" (clojure.string/join ", " (list-daum)))
    (catch Exception e (println e)))
  (. Thread sleep (* 1000 60 interval))
  (println))
 

신고
Posted by steloflute


Generate bitcoin for me

What's this?

티스토리 툴바