aboutsummaryrefslogtreecommitdiff
path: root/main.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 21:19:59 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 21:19:59 +0100
commit8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb (patch)
treecbdd20b1ac5e107f0c87f56571f11095ced0c8af /main.scm
parentMade filename attribute of all objects. (diff)
downloadcalp-8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb.tar.gz
calp-8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb.tar.xz
Move stuff between code.scm and main.scm.
Diffstat (limited to 'main.scm')
-rwxr-xr-xmain.scm63
1 files changed, 63 insertions, 0 deletions
diff --git a/main.scm b/main.scm
new file mode 100755
index 00000000..07836b04
--- /dev/null
+++ b/main.scm
@@ -0,0 +1,63 @@
+#!/usr/bin/guile \
+-e main -s
+!#
+
+(add-to-load-path ".")
+
+(load "code.scm")
+(use-modules (srfi srfi-1)
+ (srfi srfi-19)
+ (srfi srfi-26)
+ (vcalendar))
+
+;;; ------------------------------------------------------------
+
+(define (parse-dates! cal)
+;;; Parse all start times into scheme date objects.
+ (for-each (cut transform-attr! <> "DTSTART"
+ (lambda (start)
+ (localize-date
+ (string->date
+ start
+ (case (string-length start)
+ ((8) "~Y~m~d")
+ ((15) "~Y~m~dT~H~M~S")
+ ((16) "~Y~m~dT~H~M~S~z"))))))
+ (children cal 'VEVENT)))
+
+(define (search cal term)
+ (cdr (let ((events (filter (lambda (ev) (eq? 'VEVENT (type ev)))
+ (children cal))))
+ (find (lambda (ev) (string-contains-ci (car ev) term))
+ (map cons (map (cut get-attr <> "SUMMARY")
+ events)
+ events)))))
+
+
+(define (main args)
+ (define path
+ (if (null? (cdr (command-line)))
+ "testcal/d1-b.ics"
+ (cadr (command-line))))
+
+ (define cal (make-vcomponent path))
+
+
+ #; (define pizza-event (search cal "pizza"))
+
+ (parse-dates! cal)
+
+;;; Sort the events, and print a simple agenda.
+
+ (let ((sorted-events
+ (sort* (children cal 'VEVENT)
+ time<? (compose date->time-utc (extract "DTSTART")))))
+ (for-each (lambda (ev) (format #t "~a~a~a | ~a~%"
+ (if (date-today? (get-attr ev "DTSTART")) STR-YELLOW "")
+ (date->string (get-attr ev "DTSTART") "~1 ~H:~M")
+ STR-RESET
+ (get-attr ev "SUMMARY")))
+ sorted-events))
+
+
+ )