aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server.ml14
1 files changed, 11 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>.
*)
+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 =