wrong timestamp

This commit is contained in:
silva guimaraes 2025-08-03 20:24:59 -03:00
parent f613203cbe
commit 9515fa9af9
2 changed files with 57 additions and 3 deletions

View file

@ -62,6 +62,7 @@ type api_match = {
awayScore : api_score;
status : api_status;
time : api_time;
id : int;
startTimestamp : int;
}
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
@ -122,6 +123,24 @@ type api_standing = {
type api_standings_total = { standings : api_standing list }
[@@deriving yojson, show]
type api_short_match = { winnerCode : int } [@@deriving yojson]
(* type api_team_events_table = (string * api_short_match list) Hashtbl.t *)
(* [@@deriving yojson] *)
(**)
(* type api_team_events_total = { *)
(* tournamentTeamEvents : (string, api_team_events_table) Hashtbl.t *)
(* } *)
(* [@@deriving yojson] *)
type match_info = { tournament : string } [@@deriving yojson]
(* type inner_map = (string, match_info list) Hashtbl.t *)
(* [@@deriving yojson] *)
(**)
(* type outer_map = (string, inner_map) Hashtbl.t *)
(* [@@deriving yojson] *)
type normal_table_row = {
team : api_team;
position : int;
@ -165,13 +184,19 @@ type status =
[@@deriving show]
(* TODO: round info *)
type match' = { status : status; home_team : api_team; away_team : api_team }
type match' = {
status : status;
home_team : api_team;
away_team : api_team;
api_id : int;
}
[@@deriving show]
type tournament_scrape_context = {
id : int;
season : int;
name : string;
emoji : string;
filter_foreigners : bool;
timezone_offset : int option (* assumes UTC-3 if None *);
}
@ -254,7 +279,7 @@ let get url =
let req_headers =
Cohttp.Header.(
add (init ()) "X-Captcha"
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTI4NjM5MjV9.Zv5y-Ba5Kck1JPV2xTBgcfhX0YGhKq-ShTQEGAKG8Uw")
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTQzMTc2MTJ9.sMoqrrTQMoq1JJRJqn-pbOtPIOlOfh5gjrniyUKX_04")
in
let* resp, body =
Cohttp_lwt_unix.Client.get ~headers:req_headers @@ Uri.of_string url
@ -325,6 +350,7 @@ let matches_of_api_events (e : api_events) =
m.startTimestamp
in
{
api_id = m.id;
home_team = m.homeTeam;
away_team = m.awayTeam;
status =
@ -521,6 +547,7 @@ let matches_of_api_events (e : api_events) =
| _, "postponed", _ -> Postponed
| _, "suspended", _ ->
Suspended { start_timestamp = m.startTimestamp }
| _, "delayed", _ -> Delayed
| a, b, _ ->
failwith
@@ Printf.sprintf "impossible: %s %s %s" a b
@ -558,6 +585,10 @@ let fetch_all_matches ctx =
let fetch_all_tournaments tournaments =
tournaments |> List.map fetch_all_matches |> Lwt.all
let fetch_match_details id =
let url = sprintf "https://www.sofascore.com/api/v1/event/%d" id in
get url >|= Yojson.Safe.from_string
let standings context =
let url =
sprintf
@ -566,3 +597,11 @@ let standings context =
in
get url >|= Yojson.Safe.from_string >|= api_standings_total_of_yojson
>|= tables_of_api_standings_total
(* let last_five_matches context = *)
(* let url = *)
(* sprintf "https://www.sofascore.com/api/v1/unique-tournament/%d/season/%d/team-events/total" *)
(* context.id context.season *)
(* in *)
(* (* get url >|= Yojson.Safe.from_string >|= *) *)
(* ;; *)