aboutsummaryrefslogtreecommitdiff
path: root/code.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 10:33:02 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 10:33:02 +0100
commit8c5b4d4f4a0e07525efb9eb04ec99068946cdef4 (patch)
tree53830b1ea10e4dd99e9b54c16c539aa680052b60 /code.scm
parentAdd simple sorted agenda to code.scm. (diff)
downloadcalp-8c5b4d4f4a0e07525efb9eb04ec99068946cdef4.tar.gz
calp-8c5b4d4f4a0e07525efb9eb04ec99068946cdef4.tar.xz
Move load-extension to (vcalendar primitive).
Diffstat (limited to 'code.scm')
-rwxr-xr-xcode.scm19
1 files changed, 14 insertions, 5 deletions
diff --git a/code.scm b/code.scm
index 44444c3a..625b06fc 100755
--- a/code.scm
+++ b/code.scm
@@ -3,6 +3,7 @@
!#
(add-to-load-path (dirname (current-filename)))
+
(use-modules (srfi srfi-19)
(srfi srfi-26)
(vcalendar))
@@ -14,17 +15,25 @@
(define cal (make-vcomponent path))
+(define (extract field)
+ (cut get-attr <> field))
+
;;; Parse all start times into scheme date objects.
(for-each (cut transform-attr! <> "DTSTART"
(cut string->date <> "~Y~m~dT~H~M~S"))
- (children cal))
+ (children cal 'VEVENT))
+
+;;; This function borrowed from web-ics (calendar util)
+(define* (sort* items comperator #:optional (get identity))
+ "A sort function more in line with how python's sorted works"
+ (sort items (lambda (a b)
+ (comperator (get a)
+ (get b)))))
;;; Sort the events, and print a simple agenda.
(let ((sorted-events
- (sort (children cal)
- (lambda (a b)
- (time<? (date->time-utc (get-attr a "DTSTART"))
- (date->time-utc (get-attr b "DTSTART")))))))
+ (sort* (children cal 'VEVENT)
+ time<? (compose date->time-utc (extract "DTSTART")))))
(for-each (lambda (ev) (format #t "~a | ~a~%"
(date->string (get-attr ev "DTSTART") "~1 ~H:~M")
(get-attr ev "SUMMARY")))