better usage of the pattern-matching
This commit is contained in:
parent
8201e2cbe4
commit
a8248827e0
1 changed files with 14 additions and 24 deletions
|
@ -12,10 +12,8 @@ let inject_username session_id creds =
|
||||||
let input_username =
|
let input_username =
|
||||||
match find session_id strat with
|
match find session_id strat with
|
||||||
| [] -> raise (Any (fmt "Username input not found"))
|
| [] -> raise (Any (fmt "Username input not found"))
|
||||||
| _ as l ->
|
| it :: [] -> it
|
||||||
if List.length l > 1
|
| _ -> raise (Any "Too many elements found as the username input")
|
||||||
then raise (Any "Too many elements found as the username input")
|
|
||||||
else List.nth l 0
|
|
||||||
in
|
in
|
||||||
(* Insert the username *)
|
(* Insert the username *)
|
||||||
send_keys session_id input_username creds.username;
|
send_keys session_id input_username creds.username;
|
||||||
|
@ -38,10 +36,8 @@ let rec _inject_password session_id creds try_count =
|
||||||
inject_username session_id creds;
|
inject_username session_id creds;
|
||||||
_inject_password session_id creds (try_count - 1);
|
_inject_password session_id creds (try_count - 1);
|
||||||
None
|
None
|
||||||
| _ as l ->
|
| it :: [] -> Some it
|
||||||
if List.length l > 1
|
| _ -> raise (Any "Too many elements found as the password input")
|
||||||
then raise (Any "Too many elements found as the password input")
|
|
||||||
else Some (List.nth l 0)
|
|
||||||
in
|
in
|
||||||
match input_password with
|
match input_password with
|
||||||
| Some input ->
|
| Some input ->
|
||||||
|
@ -83,12 +79,10 @@ let login_twitter ctx username password secret =
|
||||||
(* Detection and injection of 2FA code if needed *)
|
(* Detection and injection of 2FA code if needed *)
|
||||||
match find ctx.session_id (CSS "input[name='text']") with
|
match find ctx.session_id (CSS "input[name='text']") with
|
||||||
| [] -> print_endline "Doesn't use 2FA as no input found"
|
| [] -> print_endline "Doesn't use 2FA as no input found"
|
||||||
| _ as l ->
|
| it :: [] ->
|
||||||
if List.length l > 1
|
if ctx.debug then print_endline "Type 2FA code...";
|
||||||
then raise (Any "Too many elements found as 2FA input")
|
inject_2fa ctx.session_id secret it
|
||||||
else (
|
| _ -> raise (Any "Too many elements found as 2FA input")
|
||||||
if ctx.debug then print_endline "Type 2FA code...";
|
|
||||||
inject_2fa ctx.session_id secret (List.nth l 0))
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let go_to_profile ctx =
|
let go_to_profile ctx =
|
||||||
|
@ -96,10 +90,8 @@ let go_to_profile ctx =
|
||||||
let profile_button =
|
let profile_button =
|
||||||
match find ctx.session_id (XPath "//a[@data-testid='AppTabBar_Profile_Link']") with
|
match find ctx.session_id (XPath "//a[@data-testid='AppTabBar_Profile_Link']") with
|
||||||
| [] -> raise (Any (fmt "Profile button not found"))
|
| [] -> raise (Any (fmt "Profile button not found"))
|
||||||
| _ as l ->
|
| it :: [] -> it
|
||||||
if List.length l > 1
|
| _ -> raise (Any "Too many profile button found")
|
||||||
then raise (Any "Too many profile button found")
|
|
||||||
else List.nth l 0
|
|
||||||
in
|
in
|
||||||
if ctx.debug then print_endline "Navigate to user replies...";
|
if ctx.debug then print_endline "Navigate to user replies...";
|
||||||
ignore
|
ignore
|
||||||
|
@ -148,18 +140,16 @@ let tweet ctx msg =
|
||||||
let tweet_area =
|
let tweet_area =
|
||||||
match find ctx.session_id (CSS "div[data-testid='tweetTextarea_0']") with
|
match find ctx.session_id (CSS "div[data-testid='tweetTextarea_0']") with
|
||||||
| [] -> raise (Any (fmt "Tweet area not found"))
|
| [] -> raise (Any (fmt "Tweet area not found"))
|
||||||
| _ as l ->
|
| it :: [] -> it
|
||||||
if List.length l > 1 then raise (Any "Too many tweet areas found") else List.nth l 0
|
| _ -> raise (Any "Too many tweet areas found")
|
||||||
in
|
in
|
||||||
send_keys ctx.session_id tweet_area msg;
|
send_keys ctx.session_id tweet_area msg;
|
||||||
Unix.sleep 2;
|
Unix.sleep 2;
|
||||||
let send_tweet_button =
|
let send_tweet_button =
|
||||||
match find ctx.session_id (XPath "//div[@data-testid='tweetButtonInline']") with
|
match find ctx.session_id (XPath "//div[@data-testid='tweetButtonInline']") with
|
||||||
| [] -> raise (Any (fmt "Tweet button not found"))
|
| [] -> raise (Any (fmt "Tweet button not found"))
|
||||||
| _ as l ->
|
| it :: [] -> it
|
||||||
if List.length l > 1
|
| _ -> raise (Any "Too many tweet button found")
|
||||||
then raise (Any "Too many tweet button found")
|
|
||||||
else List.nth l 0
|
|
||||||
in
|
in
|
||||||
click ctx.session_id send_tweet_button;
|
click ctx.session_id send_tweet_button;
|
||||||
Unix.sleep 8
|
Unix.sleep 8
|
||||||
|
|
Loading…
Reference in a new issue