From 3f415cf9e16ba35786f8becda79997808d174821 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 16 May 2023 13:32:50 +0200 Subject: [PATCH] update tweet strategy * now use the home page to tweet, instead of relying of clicking on tweet page --- bin/main.ml | 4 +++- bin/twitter.ml | 14 +++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 35b2559..dd4b64a 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -45,10 +45,12 @@ let rec check ctx = if 0 = timeout then ( if ctx.debug then print_endline "Tweeting..."; - (* Tweet and returns to profile page *) + (* Tweet *) tweet ctx "This tweet is for the Twitter's CTO: don't suspend my account for inactivity."; + (* Returns to profile page *) + go_to_profile ctx; (* Wait the maximum time since we just tweeted *) recheck max_time) else (* Wait the amount of time calculated from the post *) diff --git a/bin/twitter.ml b/bin/twitter.ml index 9a0a761..9ad4faa 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -142,16 +142,8 @@ let find_latest_tweet ctx = ;; let tweet ctx msg = - let tweet_button = - match find ctx.session_id (XPath "//a[@data-testid='SideNav_NewTweet_Button']") with - | [] -> raise (Any (fmt "Tweet button not found")) - | _ as l -> - if List.length l > 1 - then raise (Any "Too many tweet button found") - else List.nth l 0 - in - click ctx.session_id tweet_button; - Unix.sleep 2; + ignore (navigate ctx.session_id "https://twitter.com/home"); + Unix.sleep 4; let tweet_area = match find ctx.session_id (CSS "div[data-testid='tweetTextarea_0']") with | [] -> raise (Any (fmt "Tweet area not found")) @@ -161,7 +153,7 @@ let tweet ctx msg = send_keys ctx.session_id tweet_area msg; Unix.sleep 2; let send_tweet_button = - match find ctx.session_id (XPath "//div[@data-testid='tweetButton']") with + match find ctx.session_id (XPath "//div[@data-testid='tweetButtonInline']") with | [] -> raise (Any (fmt "Tweet button not found")) | _ as l -> if List.length l > 1