aboutsummaryrefslogtreecommitdiff
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
parentMade filename attribute of all objects. (diff)
downloadcalp-8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb.tar.gz
calp-8628e2bf59aa1eb0f27c04bdeaeae7adf84250cb.tar.xz
Move stuff between code.scm and main.scm.
-rwxr-xr-xcode.scm28
-rwxr-xr-xmain.scm63
2 files changed, 63 insertions, 28 deletions
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)
- 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))
-
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))
+
+
+ )