copabot/bin/main.ml
2025-06-28 17:20:12 -03:00

161 lines
3.5 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 = 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 = 70268;
name = "ARG1";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 278;
season = 71306;
name = "URY1";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 11539;
season = 70681;
name = "COL1";
filter_foreigners = false;
timezone_offset = Some ~-5;
};
{
id = 1335;
season = 76050;
name = "COPA COLOMBIA";
filter_foreigners = false;
timezone_offset = Some ~-5;
};
{
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 = 11653;
season = 71131;
name = "CHL1";
filter_foreigners = false;
timezone_offset = Some ~-4;
};
{
id = 11540;
season = 69799;
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 = Lib.fetch_all tournaments in
let today = Unix.time () |> Unix.gmtime in
let tomorrow = Unix.time () +. (60. *. 60. *. 24.) |> Unix.gmtime 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\
![since march 28th, 2025](https://count.getloli.com/@copalib)\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 "\nupdated. sleeping for 5 minutes";
Unix.sleep 300
done