aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/course.ml4
-rw-r--r--src/course.mli2
-rw-r--r--src/ics.ml49
-rw-r--r--src/ics.mli19
-rw-r--r--src/ucs.ml8
5 files changed, 61 insertions, 21 deletions
diff --git a/src/course.ml b/src/course.ml
index 3a0d1fc..fdabb50 100644
--- a/src/course.ml
+++ b/src/course.ml
@@ -68,7 +68,7 @@ let encoding =
(fun ((_id, start, stop, _allDay, description, (), (), (), (), category),
(_sites, _modules, (), (), (), (), ())) ->
let location, summary = location_and_summary description category in
- Ics.{start; stop; summary; category; location})
+ Ics.Event.make start stop summary location)
(merge_objs
(obj10
(req "id" string)
@@ -95,4 +95,4 @@ let decode s =
match s with
| "" -> `O []
| s -> Ezjsonm.from_string s in
- J.destruct (J.list encoding) toks
+ Ics.make @@ J.destruct (J.list encoding) toks
diff --git a/src/course.mli b/src/course.mli
index a91954d..054444e 100644
--- a/src/course.mli
+++ b/src/course.mli
@@ -15,4 +15,4 @@
* along with ucs. If not, see <http://www.gnu.org/licenses/>.
*)
-val decode : string -> Ics.event list
+val decode : string -> Ics.t
diff --git a/src/ics.ml b/src/ics.ml
index 5bfecb0..2ee0269 100644
--- a/src/ics.ml
+++ b/src/ics.ml
@@ -17,10 +17,45 @@
open CalendarLib
-type event = {
- start: Calendar.t;
- stop: Calendar.t;
- summary: string;
- category: string;
- location: string
- }
+let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%SZ"
+let current_date () = to_date @@ Calendar.now ()
+
+module Event = struct
+ type t = {
+ start: Calendar.t;
+ stop: Calendar.t;
+ summary: string;
+ location: string;
+ }
+
+ let make start stop summary location =
+ {start; stop; summary; location}
+
+ let to_string date event id =
+ Printf.sprintf "BEGIN:VEVENT\n\
+ UID:%s.%d@ucs.pa1ch.fr\n\
+ DTSTART:%s\n\
+ DTEND:%s\n\
+ DTSTAMP:%s\n\
+ SUMMARY:%s\n\
+ LOCATION:%s\n\
+ END:VEVENT\n"
+ date id (to_date event.start) (to_date event.stop)
+ date event.summary event.location
+end
+
+type t = Event.t list
+
+let make (events: t) = events
+
+let to_string events =
+ let date = current_date () in
+ let rec gen_events id str = function
+ | [] -> str
+ | event :: l ->
+ gen_events (id + 1) (str ^ Event.to_string date event id) l in
+ "BEGIN:VCALENDAR\n\
+ VERSION:2.0\n\
+ PRODID:-//ucs//\n"
+ ^ gen_events 0 "" events
+ ^ "END:VCALENDAR\n"
diff --git a/src/ics.mli b/src/ics.mli
index 352ce68..219f851 100644
--- a/src/ics.mli
+++ b/src/ics.mli
@@ -15,10 +15,15 @@
* along with ucs. If not, see <http://www.gnu.org/licenses/>.
*)
-type event = {
- start: CalendarLib.Calendar.t;
- stop: CalendarLib.Calendar.t;
- summary: string;
- category: string;
- location: string
- }
+module Event : sig
+ type t
+
+ val make : CalendarLib.Calendar.t -> CalendarLib.Calendar.t ->
+ string -> string -> t
+ val to_string : string -> t -> int -> string
+end
+
+type t
+
+val make : Event.t list -> t
+val to_string : t -> string
diff --git a/src/ucs.ml b/src/ucs.ml
index 121ac7a..55a246c 100644
--- a/src/ucs.ml
+++ b/src/ucs.ml
@@ -33,7 +33,7 @@ let body =
let dump_date = CalendarLib.Printer.Calendar.to_string
let () =
- let body = Lwt_main.run body in
- List.iter (fun Ics.{start; stop; summary; category; location} ->
- Printf.printf "%s\n%s\n%s\n%s\n%s\n\n" (dump_date start) (dump_date stop) summary category location)
- @@ Course.decode body
+ Lwt_main.run body
+ |> Course.decode
+ |> Ics.to_string
+ |> print_endline