From a262942eb56a962d20b3b34b637cd9cbea81b509 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 13 Sep 2020 20:12:14 +0200 Subject: server: set the range to fetch to a year and a month To fetch all interesting courses, the start date is set to a month before today, and the end date is set to a year after today. This should be enough for our iCalendar files. Signed-off-by: Alban Gruin --- src/server.ml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/server.ml b/src/server.ml index a6f0617..2c1c4b9 100644 --- a/src/server.ml +++ b/src/server.ml @@ -15,13 +15,21 @@ * along with ucs. If not, see . *) +open CalendarLib open Lwt open Cohttp open Cohttp_lwt_unix +let format_date = Printer.Date.sprint "%Y-%m-%d" and + a_month = Date.Period.make 0 1 0 and + a_year = Date.Period.make 1 0 0 + let fetch celcat_url group = + let current_date = Date.today () in + let lower_date = format_date @@ Date.rem current_date a_month and + upper_date = format_date @@ Date.add current_date a_year in let parameters = Uri.encoded_of_query - ["start", ["2020-09-01"]; "end", ["2020-10-01"]; + ["start", [lower_date]; "end", [upper_date]; "resType", ["103"]; "calView", ["month"]; "federationIds[]", [group]; "colourScheme", ["3"]] in let body = Cohttp_lwt.Body.of_string parameters and @@ -31,8 +39,8 @@ let fetch celcat_url group = Cohttp_lwt.Body.to_string body let log uri = - let datetime = CalendarLib.( - Printer.Calendar.sprint "%Y-%m-%d %H:%M:%S" @@ Calendar.now ()) in + let datetime = + Printer.Calendar.sprint "%Y-%m-%d %H:%M:%S" @@ Calendar.now () in Lwt_io.printlf "[%s] %s" datetime (Uri.path_and_query uri) let respond ?(mime="text/html; charset=utf-8") ?(status=`OK) body = -- cgit v1.2.1