Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

website lookup scripts

Name: Anonymous 2007-07-30 1:11 ID:+r8Pf0iS

PASTE YOUR WEB SITE LOOKUP SCRIPTS

Here's mine for urban dictionary

(require (lib "url.ss" "net"))

(define (http-get url)
  (let loop ((data "") (port (get-pure-port (string->url url))))
    (let ((ln (read-line port)))
      (if (not (eof-object? ln))
          (loop (string-append data ln) port)
          (begin
            (close-input-port port)
            data)))))

(define (get-definition data)
  (regexp-match (regexp "<div class=\"def_p\">[ \\n]+<p>(.*?)</p>[ \\]+<p style=\"font-style: italic\">(.*?)</p>") data))

(define (strip-definition definition)
  (let* ((br-stripped (regexp-replace* (regexp "<br />\r") definition " "))
         (a-stripped (regexp-replace* (regexp "<a href=\".*?\">(.*?)</a>") br-stripped "\\1"))
         (quot-trans (regexp-replace* (regexp "&quot;") a-stripped "\"")))
    quot-trans))

(define (html-definition term)
  (let ((http-data (http-get (string-append "http://www.urbandictionary.com/define.php?term=";
                                            (regexp-replace* " " term "+")))))
    (get-definition http-data)))

(define (limit term definition)
  (define (lowest a b) (if (< a b) a b))
  (let ((limit 256))
    (string-append (substring definition 0 (lowest (string-length definition) limit))
                   (if (> (string-length definition) limit)
                       (string-append "... [snip] more: http://www.urbandictionary.com/define.php?term="; term)
                       ""))))
 
(define (udict term)
  (let ((definition (html-definition term)))
    (if (not (eq? definition #f))
        (limit term (strip-definition (string-append (cadr definition) " Example: " (caddr definition))))
        "")))


Examples:

> (display (udict "horrorshow"))
Part of the 'Nadsat' vocabulary used by Alex in Anothony Burgess' Novel 'A Clockwork Orange', Horrorshow was derived by Burgess from the russian word 'Khorosho' meaning well or good.  Example: real horrorshow (very good)

> (display (udict "in-out in-out"))
english slang term for sex, publicized in the movie clockwork orange Example: ...so me and the other droogs were gettin ready for some of the 'ol in-out, in-out

> (display (udict "4chan"))
you have just entered the very heart, soul, and life force of the internet. this is a place beyond sanity, wild and untamed. there is nothing new here. "new" content on 4chan is not found; it is created from old material. every interesting, offensive, shoc... [snip] more: http://www.urbandictionary.com/define.php?term=4chan

Etc.

Name: Anonymous 2007-07-31 5:28 ID:SYpYZmzC

>>6

Go fuck a rake

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List