This commit is contained in:
silva guimaraes 2025-08-03 20:27:46 -03:00
parent 9515fa9af9
commit 3e6abd1ea1

View file

@ -8,6 +8,7 @@ let context: Lib.tournament_scrape_context list = [
id = 384;
season = 70083;
name = "LIBERTADORES";
emoji = "🌎";
filter_foreigners = false;
timezone_offset = None;
};
@ -15,6 +16,7 @@ let context: Lib.tournament_scrape_context list = [
id = 480;
season = 70070;
name = "SUDAMERICANA";
emoji = "🌎";
filter_foreigners = false;
timezone_offset = None;
};
@ -22,20 +24,7 @@ let context: Lib.tournament_scrape_context list = [
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";
emoji = "🇧🇷";
filter_foreigners = false;
timezone_offset = None;
};
@ -43,6 +32,31 @@ let context: Lib.tournament_scrape_context list = [
id = 325;
season = 72034;
name = "BRAZIL 1";
emoji = "🇧🇷";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 390;
season = 72603;
name = "BRAZIL 2";
emoji = "🇧🇷";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 1596;
season = 69430;
name = "COPA DO NORDESTE";
emoji = "🇧🇷";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 1024;
season = 70664;
name = "COPA ARGENTINA";
emoji = "🇦🇷";
filter_foreigners = false;
timezone_offset = None;
};
@ -50,6 +64,7 @@ let context: Lib.tournament_scrape_context list = [
id = 155;
season = 77826;
name = "ARGENTINA 1, CLAUSURA";
emoji = "🇦🇷";
filter_foreigners = false;
timezone_offset = None;
};
@ -57,6 +72,7 @@ let context: Lib.tournament_scrape_context list = [
id = 278;
season = 71306;
name = "URUGUAY 1";
emoji = "🇺🇾";
filter_foreigners = false;
timezone_offset = None;
};
@ -64,6 +80,7 @@ let context: Lib.tournament_scrape_context list = [
id = 11536;
season = 77825;
name = "COLOMBIA 1";
emoji = "🇨🇴";
filter_foreigners = false;
timezone_offset = Some ~-5;
};
@ -71,6 +88,7 @@ let context: Lib.tournament_scrape_context list = [
id = 1335;
season = 76050;
name = "COPA COLOMBIA";
emoji = "🇨🇴";
filter_foreigners = false;
timezone_offset = Some ~-5;
};
@ -78,20 +96,15 @@ let context: Lib.tournament_scrape_context list = [
id = 11653;
season = 71131;
name = "CHILE 1";
emoji = "🇨🇱";
filter_foreigners = false;
timezone_offset = Some ~-4;
};
{
id = 390;
season = 72603;
name = "BRAZIL 2";
filter_foreigners = false;
timezone_offset = None;
};
{
id = 1221;
season = 71100;
name = "COPA CHILE";
emoji = "🇨🇱";
filter_foreigners = false;
timezone_offset = Some ~-4;
};
@ -99,6 +112,7 @@ let context: Lib.tournament_scrape_context list = [
id = 11541;
season = 69831;
name = "PARAGUAY 1, CLAUSURA";
emoji = "🇵🇾";
filter_foreigners = false;
timezone_offset = None;
};
@ -131,7 +145,8 @@ let my_head title' =
(head (title (txt title')) [
style [ txt {|
:root {
--main-bg: #eee; --main-margin: 3px;
--main-bg: #eee;
--main-margin: 3px;
--celeste: #9ed1ff;
}
* {
@ -144,9 +159,17 @@ let my_head title' =
text-decoration-color: unset;
color: unset;
}
.match-table {
text-decoration: none;
transition: background-color 0.035s;
}
.match-table:last-child {
border-bottom: 0 !important
}
.match-table:hover {
background-color: var(--main-bg);
border-radius 3px 3px;
}
.standing tbody tr:nth-child(odd) {
background-color: var(--celeste);
}
@ -157,6 +180,9 @@ let my_head title' =
td:nth-child(2), thead td {
text-align: left;
}
td:nth-child(3) {
font-weight: bold;
}
|}]
])
;;
@ -171,7 +197,7 @@ let box ?style elements =
[Tyxml.Html.a_style @@ "padding: var(--main-margin); border-radius: var(--main-margin); \
margin: var(--main-margin); " ^ s]
in
Tyxml.Html.div ~a:attr elements
Tyxml.Html.section ~a:attr elements
;;
let greet (tournaments: Lib.Tournament.t list) =
@ -186,7 +212,7 @@ let greet (tournaments: Lib.Tournament.t list) =
(my_head "index")
(body [
my_header ();
main ~a:[a_style "margin: auto; display: flex; flex-direction: row;"]
main ~a:[a_style "margin: auto; display: flex; flex-direction: row; flex-wrap: wrap"]
(tournaments
|> List.filter_map @@ fun x -> (x
|> Lib.Tournament.matches
@ -205,10 +231,9 @@ let greet (tournaments: Lib.Tournament.t list) =
then None
else
Some (
div ~a:[a_class ["match-table"] ;
a_style "display: flex; justify-content: space-between; \
border-bottom: 1px black solid; margin-bottom: calc(var(--main-margin) * 2); padding; \
var(--main-margin)"]
a ~a:[a_class ["match-table"] ; a_href @@ sprintf "/match/%d" match'.api_id ;
a_style "display: flex; justify-content: space-between; border-bottom: 1px black solid; \
padding-top: calc(var(--main-margin) * 2);"]
[
div ~a:[a_style "display: flex; width: 145px; justify-content: space-between;"] [
div ~a:[] [
@ -296,7 +321,8 @@ let greet (tournaments: Lib.Tournament.t list) =
Some (box ~style:"min-width: 200px;"
[
header [
a ~a:[a_href @@ sprintf "/tournament/%d" x.context.id] [h3 [txt x.context.name]];
a ~a:[a_href @@ sprintf "/tournament/%d" x.context.id]
[h3 [txt @@ sprintf "%s %s" x.context.emoji x.context.name]];
h4 [txt @@ sprintf "(%d/%d) Today" today.tm_mon today.tm_mday];
];
main y
@ -307,11 +333,26 @@ let greet (tournaments: Lib.Tournament.t list) =
])
;;
let match_details_page _ =
let open Tyxml.Html in
html
(my_head "index")
(body [
my_header () ;
main [
box
[ ]
];
footer []
]
)
;;
let tournament_page (tournament: Lib.Tournament.t) (tables: Lib.table list) =
let open Tyxml.Html in
let my_table (t: Lib.table) =
let attr =
[a_style "border-collapse: collapse; border: 1px solid black; height: min-content";
[a_style "border-collapse: collapse; border: 1px solid black; height: min-content;";
a_class ["standing"]]
in
let tab =
@ -354,7 +395,7 @@ let tournament_page (tournament: Lib.Tournament.t) (tables: Lib.table list) =
td ~a:attr [txt @@ string_of_int position] ;
td ~a:attr [
div ~a:[a_style "display: flex; justify-content: space-between;"] @@
(div [ txt @@ team.name ]) :: match is_playing with
(div ~a:[a_style "text-wrap: nowrap"] [ txt @@ team.name ]) :: match is_playing with
| None -> []
| Some (is_home, score) -> [
let style =
@ -414,7 +455,7 @@ let tournament_page (tournament: Lib.Tournament.t) (tables: Lib.table list) =
)
in
div [
h3 ~a:[a_style "margin-bottom: var(--main-margin)"] [txt t.name] ;
h3 ~a:[a_style "margin-bottom: var(--main-margin); text-wrap: nowrap;"] [txt t.name] ;
tab ;
]
in
@ -423,9 +464,11 @@ let tournament_page (tournament: Lib.Tournament.t) (tables: Lib.table list) =
(body [
my_header () ;
main [
box [h3 [txt tournament.context.name]] ;
box ~style:"display: flex; flex-direction: row; gap: calc(var(--main-margin) * 2)" @@
List.map my_table tables
box
[
h3 ~a:[] [txt @@ sprintf "%s %s" tournament.context.emoji tournament.context.name];
div (List.rev @@ List.map my_table tables)
]
];
footer []
]
@ -443,6 +486,11 @@ Lwt_main.run begin
let* data = Lib.fetch_all_tournaments context in
Dream.html @@ html_to_string @@ greet data
end ;
Dream.get "/match/:id" begin fun request ->
let id' = int_of_string @@ Dream.param request "id" in
let* data = Lib.fetch_match_details id' in
Dream.html @@ html_to_string @@ match_details_page data
end ;
Dream.get "/tournament/:id" begin fun request ->
let id' = int_of_string @@ Dream.param request "id" in
let ctx =