From 8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 26 Feb 2019 21:19:59 +0100 Subject: Move stuff between code.scm and main.scm. --- code.scm | 28 ---------------------------- main.scm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 28 deletions(-) create mode 100755 main.scm diff --git a/code.scm b/code.scm index d6752f1f..6586a9af 100755 --- a/code.scm +++ b/code.scm @@ -1,20 +1,9 @@ -#!/usr/bin/guile \ --s -!# - (add-to-load-path (dirname (current-filename))) (use-modules (srfi srfi-19) (srfi srfi-26) (vcalendar)) -(define path - (if (null? (cdr (command-line))) - "testcal/d1-b.ics" - (cadr (command-line)))) - -(define cal (make-vcomponent path)) - (define (extract field) (cut get-attr <> field)) @@ -22,12 +11,6 @@ (time-utc->date (date->time-utc date) (date-zone-offset (current-date)))) -;;; Parse all start times into scheme date objects. -(for-each (cut transform-attr! <> "DTSTART" - (lambda (start) - (localize-date (string->date start "~Y~m~dT~H~M~S~z")))) - (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" @@ -55,14 +38,3 @@ (time<=? (date->time-utc input-date) (date->time-utc then))))) -;;; Sort the events, and print a simple agenda. -(let ((sorted-events - (sort* (children cal 'VEVENT) - timetime-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)) - 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) + timetime-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)) + + + ) -- cgit v1.2.3