move login logic to twitter file

This commit is contained in:
Mylloon 2023-05-13 19:58:48 +02:00
parent 9b5f5a0100
commit 62571b4de5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 17 additions and 8 deletions

View file

@ -1,4 +1,5 @@
(executable
(public_name pusk)
(name main)
(modules main twitter)
(libraries pusk))

View file

@ -1,6 +1,7 @@
open Pusk.Net
open Pusk.Drivers
open Pusk.Utils
open Twitter
let start driver =
let name_driver = prepare driver in
@ -14,7 +15,7 @@ let stop (driver_process, session_id) =
stop_process driver_process
;;
let main session_id =
let main ctx =
(* Load credentials *)
load_dotenv;
let username, password =
@ -24,17 +25,13 @@ let main session_id =
| None, Some _ -> raise (Any "Username not set")
| Some _, None -> raise (Any "Password not set")
in
(* Navigate to login page *)
ignore (navigate "https://twitter.com/i/flow/login" session_id);
(* Extra wait to be sure the page is loaded *)
Unix.sleep 5;
(* DEBUG *)
print_endline (fmt "%s:%s" username password)
login_twitter ctx username password
;;
let () =
let data = start (Gecko "0.33.0") in
(try main (snd data) with
let ctx = { session_id = snd data } in
(try main ctx with
| Any why -> print_endline why);
stop data
;;

9
bin/twitter.ml Normal file
View file

@ -0,0 +1,9 @@
open Pusk.Net
open Pusk.Utils
let login_twitter ctx _username _password =
(* Navigate to login page *)
ignore (navigate "https://twitter.com/i/flow/login" ctx.session_id);
(* Extra wait to be sure the page is loaded *)
Unix.sleep 5
;;

View file

@ -2,6 +2,8 @@ exception Any of string
let fmt = Printf.sprintf
type context = { session_id : string }
let load_dotenv =
(* Load variables *)
let path = "config/.env" in