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;
|
stop_process data;
|
||||||
exit
|
exit
|
||||||
(match signal with
|
(match signal with
|
||||||
| v when v = Sys.sigint -> 130
|
| v when v = Sys.sigint -> 130
|
||||||
| _ -> 1)
|
| _ -> 1)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
|
@ -89,12 +89,12 @@ let () =
|
||||||
{ session_id = snd data
|
{ session_id = snd data
|
||||||
; debug =
|
; debug =
|
||||||
(match Sys.getenv_opt "PUSK_DEBUG" with
|
(match Sys.getenv_opt "PUSK_DEBUG" with
|
||||||
| Some boolean -> if String.lowercase_ascii boolean = "true" then true else false
|
| Some boolean -> if String.lowercase_ascii boolean = "true" then true else false
|
||||||
| None -> false)
|
| None -> false)
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
if ctx.debug then print_endline "Logging is enabled";
|
if ctx.debug then print_endline "Logging is enabled";
|
||||||
(try main ctx with
|
(try main ctx with
|
||||||
| Any why -> print_endline why);
|
| Any why -> print_endline why);
|
||||||
stop data
|
stop data
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -22,7 +22,7 @@ let rec download uri dest =
|
||||||
let stream = Body.to_stream body in
|
let stream = Body.to_stream body in
|
||||||
let res =
|
let res =
|
||||||
Lwt_io.with_file ~mode:Lwt_io.output dest (fun chan ->
|
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
|
in
|
||||||
let* () = res in
|
let* () = res in
|
||||||
print_endline "Download done!";
|
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
|
match Yojson.Safe.from_string response with
|
||||||
| `Assoc fields ->
|
| `Assoc fields ->
|
||||||
(match List.assoc "value" fields with
|
(match List.assoc "value" fields with
|
||||||
| `String res ->
|
| `String res ->
|
||||||
if not (res = "complete")
|
if not (res = "complete")
|
||||||
then (
|
then (
|
||||||
Unix.sleep 2;
|
Unix.sleep 2;
|
||||||
wait_for_load session_id)
|
wait_for_load session_id)
|
||||||
| _ -> raise (Any "Error when waiting for page to load"))
|
| _ -> raise (Any "Error when waiting for page to load"))
|
||||||
| _ -> raise (Any "wait_for_load | Invalid JSON")
|
| _ -> raise (Any "wait_for_load | Invalid JSON")
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -90,22 +90,22 @@ let parser response =
|
||||||
match Yojson.Safe.from_string response with
|
match Yojson.Safe.from_string response with
|
||||||
| `Assoc fields ->
|
| `Assoc fields ->
|
||||||
(match List.assoc "value" fields with
|
(match List.assoc "value" fields with
|
||||||
| `List l ->
|
| `List l ->
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun acc x ->
|
(fun acc x ->
|
||||||
match x with
|
match x with
|
||||||
| `Assoc subfields ->
|
| `Assoc subfields ->
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun acc' (_, value) ->
|
(fun acc' (_, value) ->
|
||||||
match value with
|
match value with
|
||||||
| `String str -> str :: acc'
|
| `String str -> str :: acc'
|
||||||
| _ -> acc')
|
| _ -> acc')
|
||||||
acc
|
acc
|
||||||
subfields
|
subfields
|
||||||
| _ -> acc)
|
| _ -> acc)
|
||||||
[]
|
[]
|
||||||
l
|
l
|
||||||
| _ -> [])
|
| _ -> [])
|
||||||
| _ -> raise (Any "finder parser | Invalid JSON")
|
| _ -> 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
|
match Yojson.Safe.from_string response with
|
||||||
| `Assoc fields ->
|
| `Assoc fields ->
|
||||||
(match List.assoc "value" fields with
|
(match List.assoc "value" fields with
|
||||||
| `String href -> href
|
| `String href -> href
|
||||||
| _ as e ->
|
| _ as e ->
|
||||||
raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e))))
|
raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e))))
|
||||||
| _ -> raise (Any "get_attribute | Invalid JSON")
|
| _ -> raise (Any "get_attribute | Invalid JSON")
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue