I'm coding a script that asks the user for a time (24 hour format), and then adding 1 hour to the inputted time. Later on in my script, I add the time that it gives out onto a webpage for my testing.
Here is my code. (Time_inp
is the new time that 1 hour has been added to from input time)
import webbrowser
import pyautogui
import datetime
from datetime import timedelta
Time_inp = int(input("Enter a time ( 1hour will be added to it): "))
date_time_str = Time_inp
date_time_obj = datetime.strptime(date_time_str, '%H%H:%M%M')
finalDate = date_time_obj timedelta(hours=1)
Later in script:
# inputting new time from earlier
pyautogui.moveTo(859, 576, 1)
time.sleep(1)
pyautogui.click()
pyautogui.hotkey('ctrl', 'a')
pyautogui.typewrite(Time_inp)
pyautogui.press('enter')
time.sleep(2)
I'm not sure how to make it type out the new time (from adding 1 hour to input time) onto the webpage. I've tried a method, but lost the progress.
CodePudding user response:
You need to set actually set Time_inp to the new time. Or instead of time_inp into the typewrite method, pass in finalDate.
Time_inp = int(input("Enter a time ( 1hour will be added to it): "))
Time_inp = datetime.strptime(Time_inp , '%H%H:%M%M')
Time_inp = Time_inp timedelta(hours=1)
Time_inp = Time_inp.strftime('%H%m')