diff options
author | Alban Gruin | 2020-09-13 20:12:14 +0200 |
---|---|---|
committer | Alban Gruin | 2020-09-13 20:14:02 +0200 |
commit | a262942eb56a962d20b3b34b637cd9cbea81b509 (patch) | |
tree | de83396b8e2b0f2abc3dd746490c7dfc6ddd7df6 | |
parent | 30927e57da3dc38a8216e1df557fd8b8110b7899 (diff) |
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 <alban at pa1ch dot fr>
-rw-r--r-- | src/server.ml | 14 |
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 = |