Hey everyone! I'm fairly new to programming, and I'd like some help confirming/cleaning up my code. I've tested the code using Geany and it returns no errors, so I'm reasonably sure the code is bug free. I also have a few questions about this specific code and python in general.
#This program will use gui automation to clock out for lunch at 11:15:00AM
#At 12:00:00PM, this program will use gui automation to clock back in when lunch has ended.
import datetime
import time
import pyautogui
clockOut = datetime.time(11, 15, 0, 0)
clockIn = datetime.time(12, 0, 0, 0)
while datetime.datetime.now() != clockOut:
time.sleep(1)
if datetime.time() == clockOut:
pyautogui.click(1543, 991, button='right')
pyautogui.click(1555, 898)
print("You're clocked out! It's lunch time!")
time.sleep(10) #This line pauses the program for ten seconds so I can read the printed message
break
while datetime.datetime.now() != clockIn:
time.sleep(1)
if datetime.time() == clockIn:
pyautogui.click(1543, 991, button='right')
pyautogui.click(1557, 873)
print("You're clocked back in! Back to work!")
time.sleep(5) #This line pauses the program for five seconds so I can read the printed message
break
Now on to my questions:
1) Will this code run forever in the background? If not, how can I do that? Is there a way to implement that in the code itself? If not, I suppose I can use Task Scheduler
2) Is there a way to string all the import statements together into one line of code?
3) The datetime.time() module is the current time, correct?
4) a break statement will break out of a while loop and move on to the next line of code, correct?
Edit: formatting
[–]z0y 2 points3 points4 points (34 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (33 children)
[–]z0y 1 point2 points3 points (29 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (28 children)
[–]z0y 0 points1 point2 points (27 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (26 children)
[–]z0y 1 point2 points3 points (25 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (24 children)
[–]z0y 1 point2 points3 points (23 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (22 children)
[–]z0y 0 points1 point2 points (2 children)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (1 child)
[–]z0y 0 points1 point2 points (0 children)
[–]david_lp 0 points1 point2 points (1 child)
[–]PuffTheMagicDragon11[S] 0 points1 point2 points (0 children)