aboutsummaryrefslogtreecommitdiffstats
path: root/lib/guile/read-habit.scm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/guile/read-habit.scm')
-rwxr-xr-xlib/guile/read-habit.scm53
1 files changed, 29 insertions, 24 deletions
diff --git a/lib/guile/read-habit.scm b/lib/guile/read-habit.scm
index 7ba7002..7c04422 100755
--- a/lib/guile/read-habit.scm
+++ b/lib/guile/read-habit.scm
@@ -2,37 +2,41 @@
--listen -s
!#
-(add-to-load-path "/home/titan/dev/helpful_scripts/guile/")
+(add-to-load-path "/home/titan/dev/dotfiles/lib/guile/")
-(use-modules (ice-9 rdelim)
- (ice-9 popen)
+(use-modules (ice-9 format)
(ice-9 ftw)
- (ice-9 format)
+ (ice-9 popen)
+ (ice-9 rdelim)
+ (json)
(term ansi-color)
+ (utils)
(web request)
- (json)
(web response)
(web server)
- (web uri)
- (utils))
+ (web uri))
(define habits-dir (expand-file "~/org/habits/"))
-(define (parse-file port)
- (let loop ((values '())
- (line (read-line port)))
- (if (eof-object? line)
- (reverse values)
- (loop (cons (map string->number (string-split line #\:)) values)
- (read-line port)))))
+(define (iter-lines filename proc)
+ (call-with-input-file filename
+ (lambda (port)
+ (let loop ((values '())
+ (line (read-line port)))
+ (if (eof-object? line)
+ (reverse values)
+ (loop (cons (proc line) values)
+ (read-line port)))))))
(define (cli-print file-name)
- (map (lambda (row)
- (format #t "~a -> ~d~%"
- (colorize-string (strftime "%c" (localtime (car row))) 'CYAN 'BOLD)
- (cadr row)))
- (call-with-input-file (string-append habits-dir file-name)
- parse-file)))
+ (iter-lines
+ (string-append habits-dir file-name)
+ (lambda (line)
+ (let ((row (map string->number (string-split line #\:))))
+ (format #t "~a -> ~d~%"
+ (colorize-string (strftime "%c" (localtime (car row))) 'CYAN 'BOLD)
+ (cadr row))
+ row))))
(define (request-path-components request)
(split-and-decode-uri-path (uri-path (request-uri request))))
@@ -53,9 +57,10 @@
((file-exists? (string-append habits-dir (car path)))
(values '((content-type . (application/json)))
(scm->json-string (list->vector
- (map (lambda (row) (list->vector row))
- (call-with-input-file (string-append habits-dir (car path))
- parse-file))))))
+ (iter-lines
+ (string-append habits-dir (car path))
+ (lambda (line)
+ (list->vector (map string->number (string-split line #\:)))))))))
((string=? "hi" (car path))
(values '((content-type . (application/json)))
'(hi)))
@@ -64,5 +69,5 @@
(cli-print "pull-ups.dat")
(display "pu\n")
-(cli-print "push-ups.dat")
+(cli-print "poop.dat")
;(run-server (lambda (request request-body) (handle-request request request-body)))