Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ql:quickload :ps-experiment)
(ql:quickload :quri)
(in-package :cl-user)
(defpackage dl-image
(:use :cl
(:export main
(in-package :dl-image)
(defvar *dependencies* '("cheerio-httpcli" "request")
"Write dependent libralies of Node.js as string list")
( *client* (require "cheerio-httpcli"))
( *request* (require "request"))
( *fs* (require "fs"))
( *url* (require "url"))
( *save-dir* (+ __dirname "/img"))
( ensure-savedir ()
(unless (*fs*.exists-sync *save-dir*)
(*fs*.mkdir-sync *save-dir*)))
( url-encode (str)
(quri:url-encode str))
( download-images ()
(let ((url (+ "" (url-encode "ハムスター")))
(param (make-hash-table)))
url param
(lambda (err $ res)
(when err
(console.log "error")
(console.log err)
(-- ($ "img")
(each (lambda (idx)
(let* ((src (*url*.resolve url
(-- ($ this) (attr "src"))))
(file-name (-- (*url*.parse src) pathname))
(file-path (+ *save-dir* "/"
(file-name.replace (regex "/[^a-zA-Z0-9\\.]+/g") "_"))))
(-- (*request* src)
(pipe (*fs*.create-write-stream file-path)))))))))))
(defun main (&rest argv)
(declare (ignorable argv))
(with-use-ps-pack (:this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment