summaryrefslogtreecommitdiff
path: root/home/scripts/sync.scm
blob: a51b557d852a22ffcfdae5724848372a21b4d31b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env gosh

;; download the given files to ~/.cache/feedsync under hashed filenames
;; if the versions there are older than two hours

(use util.match)
(use gauche.process)


(define targets
  (cdr (command-line)))

(define cachedir
  (string-append (sys-getenv "HOME") "/.cache/feedsync"))

(do-process `("mkdir" "-p" ,cachedir))

(map (lambda (target)
       (let ([cachefile (format "~a/~a.ics" cachedir (portable-hash target 0))])
         (cond
           [(not (file-exists? cachefile))
            (do-process `("curl" ,target "-o" ,cachefile))]
           [(< 7200 (- (sys-time) (sys-stat->mtime (sys-stat cachefile))))
            (print (format "fetching ~a" target))
            (do-process `("curl" ,target "-o" ,cachefile))]
           [else
            (display "time limit not yet exceeded")])))
     targets)