diff --git a/bin/main.ml b/bin/main.ml index 914fb86..8773720 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -7,6 +7,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 357; season = 69619; name = "CWC"; + emoji = "🇧🇷"; filter_foreigners = true; timezone_offset = None; }; @@ -14,6 +15,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 384; season = 70083; name = "LIBERTADORES"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -21,6 +23,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 480; season = 70070; name = "SUDAMERICANA"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -28,6 +31,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 373; season = 71944; name = "COPA DO BRASIL"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -35,6 +39,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 1596; season = 69430; name = "COPA DO NORDESTE"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -42,6 +47,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 1024; season = 70664; name = "COPA ARGENTINA"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -49,6 +55,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 325; season = 72034; name = "BRA1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -56,6 +63,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 155; season = 77826; name = "ARG1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -63,6 +71,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 278; season = 71306; name = "URY1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -70,6 +79,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 11536; season = 77825; name = "COL1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = Some ~-5; }; @@ -77,6 +87,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 1335; season = 76050; name = "COPA COLOMBIA"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = Some ~-5; }; @@ -84,6 +95,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 11653; season = 71131; name = "CHL1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = Some ~-4; }; @@ -91,6 +103,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 390; season = 72603; name = "BRA2"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -98,6 +111,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 1221; season = 71100; name = "COPA CHILE"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = Some ~-4; }; @@ -105,6 +119,7 @@ let tournaments : Lib.tournament_scrape_context list = id = 11541; season = 69831; name = "PRY1"; + emoji = "🇧🇷"; filter_foreigners = false; timezone_offset = None; }; @@ -130,7 +145,7 @@ let pp (day : Unix.tm) matches = in if ppd_matches = "" then "" else - sprintf ">%s %02d/%02d:\n%s" (weekday day.tm_wday) day.tm_mday day.tm_mon + sprintf ">%s %02d/%02d:\n%s" (weekday day.tm_wday) day.tm_mday (succ day.tm_mon) ppd_matches let f () = diff --git a/lib/lib.ml b/lib/lib.ml index fa1ea02..83475ba 100644 --- a/lib/lib.ml +++ b/lib/lib.ml @@ -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 >|= *) *) +(* ;; *)