#lang racket (require net/url) (define p (get-pure-port (string->url "http://www.naver.com"))) (let loop () (define r (read-line p)) (cond [(not (eof-object? r)) (display r) (loop)]))
아래는 koscom 에서 kospi200 시세를 얻어오는 예제이다 . (showindex.rkt)
#lang racket
(require net/url)
(require racket/date)
(define (read-url url)
(port->string (reencode-input-port (get-pure-port (string->url url)) "EUC-KR")))(define (get-quote)
(define text (read-url "http://kosdb.koscom.co.kr/main/jisuticker.html"))
(define m (regexp-match #rx"KOSPI200.*>(.*) (.*) (.*)</font>" text))
(format "~a ~a~a" (list-ref m 1) (list-ref m 2) (list-ref m 3)))(displayln "KOSPI200")
(let loop ()
(displayln (format "~a ~a" (date->string (current-date) #t) (get-quote)))
(sleep 60)
(let loop ()
(unless (<= 9 (date-hour (current-date)) 14)
(sleep 60)
(loop)))
(loop))
Using thread:
#lang racket
(require net/url)
(require racket/date)
(define (read-url url)
(port->string (reencode-input-port (get-pure-port (string->url url)) "EUC-KR")))
(define (get-quote)
(define text (read-url "http://kosdb.koscom.co.kr/main/jisuticker.html"))
(define m (regexp-match #rx"KOSPI200.*>(.*) (.*) (.*)</font>" text))
(format "~a ~a~a" (list-ref m 1) (list-ref m 2) (list-ref m 3)))
(displayln "KOSPI200")
(let loop ()
(thread (lambda ()
(displayln (format "~a ~a" (date->string (current-date) #t) (get-quote)))))
(sleep 60)
(let loop ()
(unless (<= 9 (date-hour (current-date)) 14)
(sleep 60)
(loop)))
(loop))
'My Computer Programs' 카테고리의 다른 글
(Javascript) Clock (0) | 2012.09.15 |
---|---|
(Javascript) KOSPI200 시세 얻기 (0) | 2012.09.15 |
(Racket) 로또 번호 생성 (0) | 2012.09.01 |
(Python) KOSPI200 시세 얻기 (0) | 2012.08.29 |
(Python) 좌우열기 인쇄 페이지 재설정 (0) | 2012.08.29 |