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]
|
||||
|
||||
let team_name x =
|
||||
match x.short_name with
|
||||
| Some x -> x
|
||||
| None -> x.name
|
||||
let team_name x = match x.short_name with Some x -> x | None -> x.name
|
||||
|
||||
type api_tournament_info = { name : string; slug : string }
|
||||
[@@yojson.allow_extra_fields] [@@deriving yojson, show]
|
||||
|
|
@ -79,6 +76,7 @@ type status =
|
|||
| Suspended of { start_timestamp : int }
|
||||
| Postponed
|
||||
| Canceled
|
||||
| Delayed
|
||||
| InProgress of time
|
||||
| Completed of time
|
||||
[@@deriving show]
|
||||
|
|
@ -123,6 +121,7 @@ module Tournament = struct
|
|||
let timestamp =
|
||||
match x.status with
|
||||
| Postponed | Completed _ | Canceled -> None
|
||||
| Delayed -> Some "delayed... "
|
||||
| Suspended t ->
|
||||
if is_today t.start_timestamp then Some "SUS! " else None
|
||||
| InProgress t ->
|
||||
|
|
@ -146,8 +145,8 @@ module Tournament = struct
|
|||
| None -> None
|
||||
| Some timestamp ->
|
||||
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
|
||||
let m =
|
||||
tournament.matches
|
||||
|
|
@ -169,13 +168,20 @@ exception Status_Not_found
|
|||
let get url : string =
|
||||
let http_get url =
|
||||
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
|
||||
if code = 404 then raise Status_Not_found
|
||||
else if Cohttp.Code.is_success code then
|
||||
let* b = Cohttp_lwt.Body.to_string body in
|
||||
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
|
||||
Lwt_main.run
|
||||
(let* result = http_get url in
|
||||
|
|
@ -221,6 +227,7 @@ let matches_of_api_events (e : api_events) =
|
|||
| "suspended" -> Suspended { start_timestamp = m.startTimestamp }
|
||||
| "inprogress" -> InProgress t
|
||||
| "finished" -> Completed t
|
||||
| "delayed" -> Delayed
|
||||
| _ -> failwith (sprintf "unrecognized match type: %s" typ));
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ let update_page content =
|
|||
Cohttp_lwt.Body.of_form
|
||||
[
|
||||
("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" ]);
|
||||
("text", [ content ]);
|
||||
]
|
||||
|
|
@ -28,10 +29,6 @@ let update_page content =
|
|||
let uri = Uri.of_string "https://rentry.org/copalib-schedule/edit" in
|
||||
let req_headers =
|
||||
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 =
|
||||
cookies
|
||||
|> List.map (fun (x : string * Cookie.Set_cookie_hdr.t) ->
|
||||
|
|
@ -39,7 +36,17 @@ let update_page content =
|
|||
v.cookie)
|
||||
|> Cookie.Cookie_hdr.serialize
|
||||
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
|
||||
let* resp, _ =
|
||||
Cohttp_lwt_unix.Client.post uri ?body:(Some form)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue