wiggly/main.py

63 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
import pyautogui
import threading
import datetime
from random import randint
import subprocess
time_between_moves = 5.0 # How long between each move (in seconds)
move_duration = 1 # How long a move to the next coordinate should take (in seconds)
screenSize = pyautogui.size()
def get_idle_time():
"""Gets the idle time of the current user in seconds."""
output = subprocess.check_output(
"ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000)}'",
shell=True,
text=True
)
return int(output)
def rand_x():
return randint(1, screenSize[0])
def rand_y():
return randint(1, screenSize[1])
def moveMouse():
x = rand_x()
y = rand_y()
pyautogui.moveTo(x, y, duration = move_duration)
main()
#def clickMouse():
# pyautogui.click()
# main()
def doNothing():
main()
def main():
hour = datetime.datetime.now().hour
idle_time_seconds = get_idle_time()
print(f"Idle time: {idle_time_seconds} seconds")
if hour == 18:
print("end of day reached")
quit()
elif idle_time_seconds >= 15:
threading.Timer(time_between_moves, moveMouse).start()
# threading.Timer(10.0, clickMouse).start()
else:
threading.Timer(time_between_moves, doNothing).start()
main()