detect if we need to tweet or not
This commit is contained in:
parent
5575d2c2c5
commit
62b04965c3
1 changed files with 8 additions and 5 deletions
13
bin/main.ml
13
bin/main.ml
|
@ -17,6 +17,7 @@ let stop (driver_process, session_id) =
|
||||||
|
|
||||||
let rec check ctx =
|
let rec check ctx =
|
||||||
(* Loop *)
|
(* Loop *)
|
||||||
|
let max_time = 2505600 (* 29 days *) in
|
||||||
let recheck timeout =
|
let recheck timeout =
|
||||||
Unix.sleep timeout;
|
Unix.sleep timeout;
|
||||||
refresh_page ctx.session_id;
|
refresh_page ctx.session_id;
|
||||||
|
@ -27,17 +28,19 @@ let rec check ctx =
|
||||||
let timeout =
|
let timeout =
|
||||||
match find_latest_tweet ctx with
|
match find_latest_tweet ctx with
|
||||||
| Some tweet_date ->
|
| Some tweet_date ->
|
||||||
(* TODO: Get date of tweet and return time to wait before tweeting
|
(* Get date of tweet and return time to wait before tweeting *)
|
||||||
* (0 if we need to tweet) *)
|
let now = Float.to_int (Unix.time ()) in
|
||||||
print_endline (fmt "latest tweet date: %d" tweet_date);
|
let diff = now - tweet_date in
|
||||||
30000000000000000
|
if diff > max_time
|
||||||
|
then 0 (* Timeout expired *)
|
||||||
|
else max_time - diff (* Timeout for when it will expire *)
|
||||||
| None -> 0
|
| None -> 0
|
||||||
in
|
in
|
||||||
if 0 = timeout
|
if 0 = timeout
|
||||||
then (
|
then (
|
||||||
print_endline "TODO: We are tweeting here. :)";
|
print_endline "TODO: We are tweeting here. :)";
|
||||||
(* Wait the maximum time since we just tweeted *)
|
(* Wait the maximum time since we just tweeted *)
|
||||||
recheck 2505600 (* 29 days *))
|
recheck max_time)
|
||||||
else (* Wait the amount of time calculated from the post *)
|
else (* Wait the amount of time calculated from the post *)
|
||||||
recheck timeout
|
recheck timeout
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue