format
This commit is contained in:
parent
3f415cf9e1
commit
c4af201d10
3 changed files with 31 additions and 31 deletions
10
bin/main.ml
10
bin/main.ml
|
@ -76,8 +76,8 @@ let handler data (signal : int) =
|
|||
stop_process data;
|
||||
exit
|
||||
(match signal with
|
||||
| v when v = Sys.sigint -> 130
|
||||
| _ -> 1)
|
||||
| v when v = Sys.sigint -> 130
|
||||
| _ -> 1)
|
||||
;;
|
||||
|
||||
let () =
|
||||
|
@ -89,12 +89,12 @@ let () =
|
|||
{ session_id = snd data
|
||||
; debug =
|
||||
(match Sys.getenv_opt "PUSK_DEBUG" with
|
||||
| Some boolean -> if String.lowercase_ascii boolean = "true" then true else false
|
||||
| None -> false)
|
||||
| Some boolean -> if String.lowercase_ascii boolean = "true" then true else false
|
||||
| None -> false)
|
||||
}
|
||||
in
|
||||
if ctx.debug then print_endline "Logging is enabled";
|
||||
(try main ctx with
|
||||
| Any why -> print_endline why);
|
||||
| Any why -> print_endline why);
|
||||
stop data
|
||||
;;
|
||||
|
|
|
@ -22,7 +22,7 @@ let rec download uri dest =
|
|||
let stream = Body.to_stream body in
|
||||
let res =
|
||||
Lwt_io.with_file ~mode:Lwt_io.output dest (fun chan ->
|
||||
Lwt_stream.iter_s (Lwt_io.write chan) stream)
|
||||
Lwt_stream.iter_s (Lwt_io.write chan) stream)
|
||||
in
|
||||
let* () = res in
|
||||
print_endline "Download done!";
|
||||
|
|
50
lib/net.ml
50
lib/net.ml
|
@ -67,12 +67,12 @@ let rec wait_for_load session_id =
|
|||
match Yojson.Safe.from_string response with
|
||||
| `Assoc fields ->
|
||||
(match List.assoc "value" fields with
|
||||
| `String res ->
|
||||
if not (res = "complete")
|
||||
then (
|
||||
Unix.sleep 2;
|
||||
wait_for_load session_id)
|
||||
| _ -> raise (Any "Error when waiting for page to load"))
|
||||
| `String res ->
|
||||
if not (res = "complete")
|
||||
then (
|
||||
Unix.sleep 2;
|
||||
wait_for_load session_id)
|
||||
| _ -> raise (Any "Error when waiting for page to load"))
|
||||
| _ -> raise (Any "wait_for_load | Invalid JSON")
|
||||
;;
|
||||
|
||||
|
@ -90,22 +90,22 @@ let parser response =
|
|||
match Yojson.Safe.from_string response with
|
||||
| `Assoc fields ->
|
||||
(match List.assoc "value" fields with
|
||||
| `List l ->
|
||||
List.fold_left
|
||||
(fun acc x ->
|
||||
match x with
|
||||
| `Assoc subfields ->
|
||||
List.fold_left
|
||||
(fun acc' (_, value) ->
|
||||
match value with
|
||||
| `String str -> str :: acc'
|
||||
| _ -> acc')
|
||||
acc
|
||||
subfields
|
||||
| _ -> acc)
|
||||
[]
|
||||
l
|
||||
| _ -> [])
|
||||
| `List l ->
|
||||
List.fold_left
|
||||
(fun acc x ->
|
||||
match x with
|
||||
| `Assoc subfields ->
|
||||
List.fold_left
|
||||
(fun acc' (_, value) ->
|
||||
match value with
|
||||
| `String str -> str :: acc'
|
||||
| _ -> acc')
|
||||
acc
|
||||
subfields
|
||||
| _ -> acc)
|
||||
[]
|
||||
l
|
||||
| _ -> [])
|
||||
| _ -> raise (Any "finder parser | Invalid JSON")
|
||||
;;
|
||||
|
||||
|
@ -151,9 +151,9 @@ let get_attribute session_id element_id attribute =
|
|||
match Yojson.Safe.from_string response with
|
||||
| `Assoc fields ->
|
||||
(match List.assoc "value" fields with
|
||||
| `String href -> href
|
||||
| _ as e ->
|
||||
raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e))))
|
||||
| `String href -> href
|
||||
| _ as e ->
|
||||
raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e))))
|
||||
| _ -> raise (Any "get_attribute | Invalid JSON")
|
||||
;;
|
||||
|
||||
|
|
Loading…
Reference in a new issue