Hello,
I put here some codes written in few hours. It's self-documented. I'm
a newbie (please skish hackers, a good tutorial would be very
convenient !). I've discovering this wonderful shell two weeks
ago. Please, skish wizards, take a look on this code. I would like to
improve it, and add many features : is someone interested ?
Thanks a lot
---------------------------------
; REQUEST FOR DEVELOPPING
; The general problem is to control (canalize) the dataflow coming
; from Internet : downloading files, and bookmarking sites
; This script should be considered as a "bootstrap", to resolve this problem
; This script would like to be ready to debug/use
; saidani@info.unicaen.fr
; I use Emacs Scheme mode
; M-x compile
; use "scsh -s file-split.scm" command
;; my User File Hierarchy Standard (UFHS ;-)
;; I use a usenet-like hierarchy to organize my directory
; comp
; comp/lang
; comp/lang/smalltalk
; comp/lang/lisp
; ...
; misc
; tmp
; when I download a file about lisp, I prefix it with "lisp-"
; So splitting process could be more easier
;; todo : permit the ~ symbol...
(define file-split-inbox '("/home/saidani/sandbox"))
;; example : lisp-gw0012.ps (I usually add a prefix)
;; ext : extension
;; base : basename
;; prefix: prefix
;; all : take a regexp
;; I try to stay close to gnus splitting way.
;; todo: just write the "articles" instead the whole path.
(define file-split-rules '(
(ext "mp3" "/home/saidani/sandbox/mp3")
(ext "zip" "/home/saidani/sandbox/zip")
(base "article" "/home/saidani/sandbox/articles")))
;; usecase : (file-extension? "music.mp" "mp3") returns #f
;; test ok
(define (file-extension? fname ext)
(if (regexp-search? (rx ,ext) (file-name-extension fname)) #t #f))
;; usecase : (file-basename? "article-scheme.ps" "article") returns #t
;; test ok
(define (file-basename? fname base)
(if (regexp-search? (rx ,base) (file-name-sans-extension fname)) #t #f))
;; Return nil if not match, else return a list of possible destination
;; Problem, it returns '( '() '() ...)... hmm. Dirty, no ?
(define (file-split-match fname)
(map
(lambda (rules)
(cond ((equal? (car rules) 'ext)
(if (file-extension? fname (cadr rules)) (caddr rules) '()))
((equal? (car rules) 'base)
(if (file-basename? fname (cadr rules)) (caddr rules) '()))
))
file-split-rules))
; Take the first matching destination
; todo: if the dest doesn't exist, create it.
; no move, for the moment, only debugging
; I work on a sandbox directory
; ls give : article article-azerty.ps coucou bonjour mp3/ mp3file mus.mp3
file-split.scm
(define (move-file src dest)
(if (not (null? dest)) (format #t "move ~a to ~a~%" src (car dest))))
; Splitting process according split-rules
(with-cwd (car file-split-inbox)
(for-each
(lambda (fname)
(format #t "file :~a~%" fname) ; debug information
(move-file fname (delete '() (file-split-match fname))))
(directory-files)))
------------------------
(define bookmark-split-inbox '("/home/saidani/sandbox/bookmarks.html"))
; First, purify inbox : html->list
; a list of anchor and title '( (anchor title) ...)
; we want a new list and add directory
; example '( ("http://www.test.fr" "Lisp User Group") ("http://www.retest.fr"
"Skish"))
; and output '( ("comp/lang/lisp"
;; ("http://www.test.fr" "Lisp User Group")
("http://www.retest.fr" "Skish"))...)
; Last, transform list->html
(define book (run/strings (cat bookmarks.html)))
(define test (nth book 10))
(define foo (match:substring (regexp-search (rx (: "file://" (* any) "html" ))
test)))
(display foo)
(newline)
--
Samir SAIDANI
Doctorant en informatique web :
http://www.info.unicaen.fr/~saidani
Universite de Caen - Laboratoire GREYC tel : 02-31-56-74-30
Equipe SMILE - Campus II - 14032 Caen Cedex fax : 02-31-56-76-30
|