Skip to content

Commit

Permalink
address comments left by @ErikBjare on #33 (feat: add toml config and…
Browse files Browse the repository at this point in the history
… arg parsing for poll time);
  • Loading branch information
ellipsis-dev[bot] authored Jul 1, 2024
1 parent 6a0175d commit 89b00a5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/aw_watcher_input/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from time import sleep

import aw_client
import click
from aw_core import Event
from aw_watcher_afk.listeners import KeyboardListener, MouseListener

logger = logging.getLogger(__name__)

def main(args, testing: bool):
@click.command()
@click.option("--testing", is_flag=True) testing: bool

Check failure

Code scanning / CodeQL

Syntax error Error

Syntax Error (in Python 3).
def main(testing: bool):
logging.basicConfig(level=logging.INFO)
logger.info("aw_watcher_input started" + (" in testing mode" if testing else ""))
client = aw_client.ActivityWatchClient("aw-watcher-input", testing=testing)
Expand All @@ -30,9 +33,9 @@ def main(args, testing: bool):
last_run = now

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

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

pulsetime = 0.0
if all(map(lambda v: v == 0, merged_data.values())):
pulsetime = args.poll_time + 0.1
pulsetime = poll_time + 0.1
logger.info("No new input")
else:
logger.info(f"New input: {e}")

client.heartbeat(bucket_name, e, pulsetime=pulsetime, queued=True)
client.heartbeat(bucket_name, e, pulsetime=pulsetime, queued=True)

0 comments on commit 89b00a5

Please sign in to comment.