168 lines
3.7 KiB
OCaml
168 lines
3.7 KiB
OCaml
open Printf
|
|
open Api
|
|
|
|
let tournaments : Lib.tournament_scrape_context list =
|
|
[
|
|
{
|
|
id = 357;
|
|
season = 69619;
|
|
name = "CWC";
|
|
filter_foreigners = true;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 384;
|
|
season = 70083;
|
|
name = "LIBERTADORES";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 480;
|
|
season = 70070;
|
|
name = "SUDAMERICANA";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 373;
|
|
season = 71944;
|
|
name = "COPA DO BRASIL";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 1596;
|
|
season = 69430;
|
|
name = "COPA DO NORDESTE";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 1024;
|
|
season = 70664;
|
|
name = "COPA ARGENTINA";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 325;
|
|
season = 72034;
|
|
name = "BRA1";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 155;
|
|
season = 77826;
|
|
name = "ARG1";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 278;
|
|
season = 71306;
|
|
name = "URY1";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 11536;
|
|
season = 77825;
|
|
name = "COL1";
|
|
filter_foreigners = false;
|
|
timezone_offset = Some ~-5;
|
|
};
|
|
{
|
|
id = 1335;
|
|
season = 76050;
|
|
name = "COPA COLOMBIA";
|
|
filter_foreigners = false;
|
|
timezone_offset = Some ~-5;
|
|
};
|
|
{
|
|
id = 11653;
|
|
season = 71131;
|
|
name = "CHL1";
|
|
filter_foreigners = false;
|
|
timezone_offset = Some ~-4;
|
|
};
|
|
{
|
|
id = 390;
|
|
season = 72603;
|
|
name = "BRA2";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
{
|
|
id = 1221;
|
|
season = 71100;
|
|
name = "COPA CHILE";
|
|
filter_foreigners = false;
|
|
timezone_offset = Some ~-4;
|
|
};
|
|
{
|
|
id = 11541;
|
|
season = 69831;
|
|
name = "PRY1";
|
|
filter_foreigners = false;
|
|
timezone_offset = None;
|
|
};
|
|
]
|
|
|
|
let pp (day : Unix.tm) matches =
|
|
let pp_matches matches =
|
|
matches
|
|
|> List.map (Lib.Tournament.pp day)
|
|
|> List.filter (( <> ) "")
|
|
|> String.concat "\n\n"
|
|
in
|
|
let ppd_matches = pp_matches matches in
|
|
let weekday = function
|
|
| 0 -> "sunday"
|
|
| 1 -> "monday"
|
|
| 2 -> "tuesday"
|
|
| 3 -> "wednesday"
|
|
| 4 -> "thursday"
|
|
| 5 -> "sexday"
|
|
| 6 -> "saturday"
|
|
| _ -> failwith "impossible"
|
|
in
|
|
if ppd_matches = "" then ""
|
|
else
|
|
sprintf ">%s %02d/%02d:\n%s" (weekday day.tm_wday) day.tm_mday day.tm_mon
|
|
ppd_matches
|
|
|
|
let f () =
|
|
let fetched = Lwt_main.run @@ Lib.fetch_all_tournaments tournaments in
|
|
let today = Unix.time () |> Unix.localtime in
|
|
let tomorrow = Unix.time () +. (60. *. 60. *. 24.) |> Unix.localtime in
|
|
let header = "### schedules" in
|
|
let schedules =
|
|
match (pp today fetched, pp tomorrow fetched) with
|
|
| "", "" -> ""
|
|
| "", b -> b
|
|
| a, "" -> a
|
|
| a, b -> sprintf "%s\n\n%s" a b
|
|
in
|
|
let footer =
|
|
"the script messes up with the bottom right views counter so here's a more \
|
|
realiable source:\n\n\
|
|
\n\n\
|
|
check these [useful links](https://rentry.org/copalib) at the main page\n\n\
|
|
***\n"
|
|
in
|
|
let md =
|
|
sprintf "%s\n\n```text\n%s\n\nUTC-3/[local time]\n```\n\n%s" header
|
|
schedules footer
|
|
in
|
|
(* print_endline md *)
|
|
Rentry.update_page md
|
|
;;
|
|
|
|
while true do
|
|
print_endline "fetching matches...";
|
|
f ();
|
|
print_endline "updated. sleeping for 5 minutes";
|
|
Unix.sleep 300
|
|
done
|