2023-05-13 10:15:35 +02:00
|
|
|
open Pusk.Net
|
|
|
|
open Pusk.Drivers
|
2023-05-13 18:00:57 +02:00
|
|
|
open Pusk.Utils
|
|
|
|
|
2023-05-13 13:06:15 +02:00
|
|
|
let start driver =
|
|
|
|
let name_driver = prepare driver in
|
|
|
|
let data_driver = run_process name_driver [] in
|
|
|
|
let session_id = get_session () in
|
|
|
|
data_driver, session_id
|
2023-05-13 10:15:35 +02:00
|
|
|
;;
|
2023-05-12 20:30:02 +02:00
|
|
|
|
2023-05-13 13:06:15 +02:00
|
|
|
let stop (driver_process, session_id) =
|
2023-05-13 13:33:46 +02:00
|
|
|
if not (close_session session_id) then print_endline "Can't close the session";
|
2023-05-13 11:59:09 +02:00
|
|
|
stop_process driver_process
|
2023-05-12 19:36:27 +02:00
|
|
|
;;
|
2023-05-13 13:06:15 +02:00
|
|
|
|
2023-05-13 16:17:18 +02:00
|
|
|
let main session_id =
|
2023-05-13 18:00:57 +02:00
|
|
|
(* Load credentials *)
|
|
|
|
load_dotenv;
|
|
|
|
let username, password =
|
|
|
|
match Sys.getenv_opt "TWITTER_USERNAME", Sys.getenv_opt "TWITTER_PASSWORD" with
|
|
|
|
| Some u, Some p -> u, p
|
|
|
|
| None, None -> raise (Any "Username and password not set")
|
|
|
|
| None, Some _ -> raise (Any "Username not set")
|
|
|
|
| Some _, None -> raise (Any "Password not set")
|
|
|
|
in
|
|
|
|
(* Navigate to login page *)
|
2023-05-13 17:10:19 +02:00
|
|
|
ignore (navigate "https://twitter.com/i/flow/login" session_id);
|
|
|
|
(* Extra wait to be sure the page is loaded *)
|
2023-05-13 18:00:57 +02:00
|
|
|
Unix.sleep 5;
|
|
|
|
(* DEBUG *)
|
|
|
|
print_endline (fmt "%s:%s" username password)
|
2023-05-13 16:17:18 +02:00
|
|
|
;;
|
2023-05-13 13:06:15 +02:00
|
|
|
|
|
|
|
let () =
|
|
|
|
let data = start (Gecko "0.33.0") in
|
2023-05-13 18:00:57 +02:00
|
|
|
(try main (snd data) with
|
|
|
|
| Any why -> print_endline why);
|
2023-05-13 13:06:15 +02:00
|
|
|
stop data
|
|
|
|
;;
|