captcha
This commit is contained in:
parent
86f8051e3b
commit
64368b1651
2 changed files with 29 additions and 15 deletions
23
lib/lib.ml
23
lib/lib.ml
|
|
@ -24,10 +24,7 @@ type api_team = {
|
||||||
}
|
}
|
||||||
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
|
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
|
||||||
|
|
||||||
let team_name x =
|
let team_name x = match x.short_name with Some x -> x | None -> x.name
|
||||||
match x.short_name with
|
|
||||||
| Some x -> x
|
|
||||||
| None -> x.name
|
|
||||||
|
|
||||||
type api_tournament_info = { name : string; slug : string }
|
type api_tournament_info = { name : string; slug : string }
|
||||||
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
|
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
|
||||||
|
|
@ -79,6 +76,7 @@ type status =
|
||||||
| Suspended of { start_timestamp : int }
|
| Suspended of { start_timestamp : int }
|
||||||
| Postponed
|
| Postponed
|
||||||
| Canceled
|
| Canceled
|
||||||
|
| Delayed
|
||||||
| InProgress of time
|
| InProgress of time
|
||||||
| Completed of time
|
| Completed of time
|
||||||
[@@deriving show]
|
[@@deriving show]
|
||||||
|
|
@ -123,6 +121,7 @@ module Tournament = struct
|
||||||
let timestamp =
|
let timestamp =
|
||||||
match x.status with
|
match x.status with
|
||||||
| Postponed | Completed _ | Canceled -> None
|
| Postponed | Completed _ | Canceled -> None
|
||||||
|
| Delayed -> Some "delayed... "
|
||||||
| Suspended t ->
|
| Suspended t ->
|
||||||
if is_today t.start_timestamp then Some "SUS! " else None
|
if is_today t.start_timestamp then Some "SUS! " else None
|
||||||
| InProgress t ->
|
| InProgress t ->
|
||||||
|
|
@ -146,8 +145,8 @@ module Tournament = struct
|
||||||
| None -> None
|
| None -> None
|
||||||
| Some timestamp ->
|
| Some timestamp ->
|
||||||
Some
|
Some
|
||||||
(sprintf "%s | %s x %s" timestamp (team_name x.home_team) (team_name x.away_team)
|
(sprintf "%s | %s x %s" timestamp (team_name x.home_team)
|
||||||
)
|
(team_name x.away_team))
|
||||||
in
|
in
|
||||||
let m =
|
let m =
|
||||||
tournament.matches
|
tournament.matches
|
||||||
|
|
@ -169,13 +168,20 @@ exception Status_Not_found
|
||||||
let get url : string =
|
let get url : string =
|
||||||
let http_get url =
|
let http_get url =
|
||||||
Stdlib.flush Stdlib.stdout;
|
Stdlib.flush Stdlib.stdout;
|
||||||
let* resp, body = Cohttp_lwt_unix.Client.get (Uri.of_string url) in
|
let req_headers =
|
||||||
|
Cohttp.Header.(
|
||||||
|
add (init ()) "X-Captcha"
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTI0OTgxMTR9.sZk2yhTk5TeWu_kXE7RO__LDYKlPgZuaA7KKFsB_0GQ")
|
||||||
|
in
|
||||||
|
let* resp, body =
|
||||||
|
Cohttp_lwt_unix.Client.get ~headers:req_headers @@ Uri.of_string url
|
||||||
|
in
|
||||||
let code = resp |> Cohttp.Response.status |> Cohttp.Code.code_of_status in
|
let code = resp |> Cohttp.Response.status |> Cohttp.Code.code_of_status in
|
||||||
if code = 404 then raise Status_Not_found
|
if code = 404 then raise Status_Not_found
|
||||||
else if Cohttp.Code.is_success code then
|
else if Cohttp.Code.is_success code then
|
||||||
let* b = Cohttp_lwt.Body.to_string body in
|
let* b = Cohttp_lwt.Body.to_string body in
|
||||||
Lwt.return (Ok b)
|
Lwt.return (Ok b)
|
||||||
else Lwt.return (Error (Cohttp.Code.reason_phrase_of_code code))
|
else Lwt.return @@ Error (Cohttp.Code.reason_phrase_of_code code)
|
||||||
in
|
in
|
||||||
Lwt_main.run
|
Lwt_main.run
|
||||||
(let* result = http_get url in
|
(let* result = http_get url in
|
||||||
|
|
@ -221,6 +227,7 @@ let matches_of_api_events (e : api_events) =
|
||||||
| "suspended" -> Suspended { start_timestamp = m.startTimestamp }
|
| "suspended" -> Suspended { start_timestamp = m.startTimestamp }
|
||||||
| "inprogress" -> InProgress t
|
| "inprogress" -> InProgress t
|
||||||
| "finished" -> Completed t
|
| "finished" -> Completed t
|
||||||
|
| "delayed" -> Delayed
|
||||||
| _ -> failwith (sprintf "unrecognized match type: %s" typ));
|
| _ -> failwith (sprintf "unrecognized match type: %s" typ));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ let update_page content =
|
||||||
Cohttp_lwt.Body.of_form
|
Cohttp_lwt.Body.of_form
|
||||||
[
|
[
|
||||||
("csrfmiddlewaretoken", [ value ]);
|
("csrfmiddlewaretoken", [ value ]);
|
||||||
("edit_code", [ "foo perro bar caca" ]); (* TODO: use environmental variables *)
|
(* TODO: use environmental variables *)
|
||||||
|
("edit_code", [ "foo perro bar caca" ]);
|
||||||
("metadata", [ "ACCESS_RECOMMENDED_THEME=dark" ]);
|
("metadata", [ "ACCESS_RECOMMENDED_THEME=dark" ]);
|
||||||
("text", [ content ]);
|
("text", [ content ]);
|
||||||
]
|
]
|
||||||
|
|
@ -28,10 +29,6 @@ let update_page content =
|
||||||
let uri = Uri.of_string "https://rentry.org/copalib-schedule/edit" in
|
let uri = Uri.of_string "https://rentry.org/copalib-schedule/edit" in
|
||||||
let req_headers =
|
let req_headers =
|
||||||
Cohttp.Header.(
|
Cohttp.Header.(
|
||||||
let h0 = init () in
|
|
||||||
let h1 = add h0 "Referer" "https://rentry.org" in
|
|
||||||
let h2 = add h1 "Content-Type" "application/x-www-form-urlencoded" in
|
|
||||||
let h3 = add h2 "User-Agent" "copabot/0.1.0" in
|
|
||||||
let hname, hvalue =
|
let hname, hvalue =
|
||||||
cookies
|
cookies
|
||||||
|> List.map (fun (x : string * Cookie.Set_cookie_hdr.t) ->
|
|> List.map (fun (x : string * Cookie.Set_cookie_hdr.t) ->
|
||||||
|
|
@ -39,7 +36,17 @@ let update_page content =
|
||||||
v.cookie)
|
v.cookie)
|
||||||
|> Cookie.Cookie_hdr.serialize
|
|> Cookie.Cookie_hdr.serialize
|
||||||
in
|
in
|
||||||
add h3 hname hvalue)
|
let rec aux h = function
|
||||||
|
| [] -> h
|
||||||
|
| (k, v) :: tail -> aux (add h k v) tail
|
||||||
|
in
|
||||||
|
aux (init ())
|
||||||
|
[
|
||||||
|
("Referer", "https://rentry.org");
|
||||||
|
("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
( "User-Agent", "copabot/0.1.0" );
|
||||||
|
(hname, hvalue);
|
||||||
|
])
|
||||||
in
|
in
|
||||||
let* resp, _ =
|
let* resp, _ =
|
||||||
Cohttp_lwt_unix.Client.post uri ?body:(Some form)
|
Cohttp_lwt_unix.Client.post uri ?body:(Some form)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue