Skip to content

Commit 89b00a5

Browse files
address comments left by @ErikBjare on #33 (feat: add toml config and arg parsing for poll time);
1 parent 6a0175d commit 89b00a5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/aw_watcher_input/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from time import sleep
44

55
import aw_client
6+
import click
67
from aw_core import Event
78
from aw_watcher_afk.listeners import KeyboardListener, MouseListener
89

910
logger = logging.getLogger(__name__)
1011

11-
def main(args, testing: bool):
12+
@click.command()
13+
@click.option("--testing", is_flag=True) testing: bool
14+
def main(testing: bool):
1215
logging.basicConfig(level=logging.INFO)
1316
logger.info("aw_watcher_input started" + (" in testing mode" if testing else ""))
1417
client = aw_client.ActivityWatchClient("aw-watcher-input", testing=testing)
@@ -30,9 +33,9 @@ def main(args, testing: bool):
3033
last_run = now
3134

3235
# we want to ensure that the polling happens with a predictable cadence
33-
time_to_sleep = args.poll_time - datetime.now().timestamp() % args.poll_time
36+
time_to_sleep = poll_time - datetime.now().timestamp() % poll_time
3437
# ensure that the sleep time is between 0 and poll_time (if system time is changed, this might be negative)
35-
time_to_sleep = max(min(time_to_sleep, args.poll_time), 0)
38+
time_to_sleep = max(min(time_to_sleep, poll_time), 0)
3639
sleep(time_to_sleep)
3740

3841
now = datetime.now(tz=timezone.utc)
@@ -48,9 +51,9 @@ def main(args, testing: bool):
4851

4952
pulsetime = 0.0
5053
if all(map(lambda v: v == 0, merged_data.values())):
51-
pulsetime = args.poll_time + 0.1
54+
pulsetime = poll_time + 0.1
5255
logger.info("No new input")
5356
else:
5457
logger.info(f"New input: {e}")
5558

56-
client.heartbeat(bucket_name, e, pulsetime=pulsetime, queued=True)
59+
client.heartbeat(bucket_name, e, pulsetime=pulsetime, queued=True)

0 commit comments

Comments
 (0)