Setup routine, adding skeleton for finding latest tweet and for check
Adding refresh call
This commit is contained in:
parent
0511907097
commit
a48594ad2f
3 changed files with 42 additions and 2 deletions
30
bin/main.ml
30
bin/main.ml
|
@ -15,6 +15,32 @@ let stop (driver_process, session_id) =
|
|||
stop_process driver_process
|
||||
;;
|
||||
|
||||
let rec check ctx =
|
||||
(* Loop *)
|
||||
let recheck timeout =
|
||||
Unix.sleep timeout;
|
||||
refresh_page ctx.session_id;
|
||||
Unix.sleep 4;
|
||||
check ctx
|
||||
in
|
||||
(* Time to wait until next check *)
|
||||
let timeout =
|
||||
match find_latest_tweet ctx with
|
||||
| Some _tweet ->
|
||||
(* TODO: Get date of tweet and return time to wait before tweeting
|
||||
* (0 if we need to tweet) *)
|
||||
30000000000000000
|
||||
| None -> 0
|
||||
in
|
||||
if 0 = timeout
|
||||
then (
|
||||
print_endline "TODO: We are tweeting here. :)";
|
||||
(* Wait the maximum time since we just tweeted *)
|
||||
recheck 2505600 (* 29 days *))
|
||||
else (* Wait the amount of time calculated from the post *)
|
||||
recheck timeout
|
||||
;;
|
||||
|
||||
let main ctx =
|
||||
(* Load credentials *)
|
||||
load_dotenv;
|
||||
|
@ -26,7 +52,9 @@ let main ctx =
|
|||
| Some _, None -> raise (Any "Password not set")
|
||||
in
|
||||
login_twitter ctx username password (Sys.getenv_opt "TWITTER_TOTP");
|
||||
go_to_profile ctx
|
||||
go_to_profile ctx;
|
||||
(* Start check routine *)
|
||||
check ctx
|
||||
;;
|
||||
|
||||
let handler data (signal : int) =
|
||||
|
|
|
@ -102,4 +102,11 @@ let go_to_profile ctx =
|
|||
Unix.sleep 4
|
||||
;;
|
||||
|
||||
let find_latest_tweet = ()
|
||||
let find_latest_tweet ctx =
|
||||
match find ctx.session_id (XPath "//article[@data-testid='tweet']") with
|
||||
| [] -> None
|
||||
| _ as tweets ->
|
||||
(* TODO: Find latest tweet *)
|
||||
List.iter print_endline tweets;
|
||||
Some "" (* tmp *)
|
||||
;;
|
||||
|
|
|
@ -141,3 +141,8 @@ let get_url session_id button_id =
|
|||
raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e))))
|
||||
| _ -> raise (Any "get_url | Invalid JSON")
|
||||
;;
|
||||
|
||||
let refresh_page ?(wait = true) session_id =
|
||||
ignore (execute_post_request (fmt "%s/refresh" (driver session_id)) Json.empty);
|
||||
if wait then wait_for_load session_id
|
||||
;;
|
||||
|
|
Loading…
Reference in a new issue