Paste: image downloader example

Author: m
Mode: factor
Date: Tue, 21 Jun 2011 11:15:36
Plain Text |
! Copyright (C) 2011 Mukhamed Karanashev.
! See http://factorcode.org/license.txt for BSD license.
USING: formatting http.client io.encodings.binary io.files kernel
locals math.parser math.ranges sequences ;
IN: zyoloader

CONSTANT: BASE-URL "http://lehazyo.ru/albums/phictures/"
CONSTANT: EXTENSION ".jpg"

: image-name ( n -- s )
    "%03d.jpg" sprintf ;

: image-url ( n -- url )
    number>string BASE-URL EXTENSION surround ;

: get-image ( n -- image )
    image-url http-get nip ;

: load-image ( n dir -- )
    swap [ get-image ] [ image-name ] bi
    rot prepend
    binary set-file-contents ;

:: load-images ( from to dir -- )
    from to [a,b] [ dir load-image ] each ;

: load-all ( -- )
    1 165 "C:/temp/zyo/" load-images ;

New Annotation

Summary:
Author:
Mode:
Body: