I want to loop my code when it reaches the end and move the set time forward by 2 hours whenever the code loops to beginning. How could I do it with existing code? Editing the code as per 1st suggestion and adding loop:
import pynput
from datetime import datetime, timedelta
from threading import Timer
from pynput.keyboard import Key, Controller
import schedule
import time
count = 0
while count <3:
x=datetime.today()
y=x.replace(day=x.day 0, hour=16, minute=37, second=00, microsecond=0)
delta_t=y-x
secs=delta_t.seconds 0.02
keyboard = Controller()
def bump():
keyboard.type("!d bump")
time.sleep (.1)
keyboard.press(Key.enter)
time.sleep (.1)
keyboard.release(Key.enter)
t = Timer(secs, bump)
t.start()
plus2 = x timedelta(hours=2)
count =1
t = Timer(secs, bump)
t.start()
CodePudding user response:
Use timedelta
.
from datetime import datetime, timedelta
now = datetime.today()
plus2 = now timedelta(hours=2)