Alright, I am trying to write a VERY simple script to perform a few things for my coworkers.
The script has a multifunction. For my team, it simply subtracts 'seconds' between the timestamps of 2 server backups (server qualification testing). For the data protection team, it will take the 2 'epoch' timestamps and convert them to a readable date/time field.
I wrote it to loop at the end, pending user interaction. My issue is, I want it to specifically only accept a 'y' or a 'n'. As it is in the current stage, it will dump out of the script if an 'n' is entered, but it will repeat if any other key is pressed, not just 'y'.
Also, if someone can let me know if there is a command that will pause it at the end and prompt for the enter key to close, otherwise, what I have works.
(note: I convert it to an exe so it runs in DOS on our laptops, so thats why there are so many "prints" so that there are some line separation)
The script has a multifunction. For my team, it simply subtracts 'seconds' between the timestamps of 2 server backups (server qualification testing). For the data protection team, it will take the 2 'epoch' timestamps and convert them to a readable date/time field.
I wrote it to loop at the end, pending user interaction. My issue is, I want it to specifically only accept a 'y' or a 'n'. As it is in the current stage, it will dump out of the script if an 'n' is entered, but it will repeat if any other key is pressed, not just 'y'.
Also, if someone can let me know if there is a command that will pause it at the end and prompt for the enter key to close, otherwise, what I have works.
(note: I convert it to an exe so it runs in DOS on our laptops, so thats why there are so many "prints" so that there are some line separation)
Code:
import time
print
print ""
print
print ""
print ""
print
print
loop = True
while loop:
bstate = True
while bstate:
try:
begin = float(raw_input("Enter the beginning seconds: "))
begin_string = time.gmtime(begin)
print
except ValueError:
print
print "Not a valid entry. Try again."
print
else:
bstate = False
print
estate = True
while estate:
try:
end = float(raw_input("Enter the end seconds (if no end time, enter 0): "))
end_string = time.gmtime(end)
print
except ValueError:
print
print "Not a valid entry. Try again."
print
else:
estate = False
difference = begin - end
begin_struct = time.strftime('%a %m/%d/%Y, %I:%M:%S %p', begin_string)
end_struct = time.strftime('%a %m/%d/%Y, %I:%M:%S %p', end_string)
print
print
print "The difference in seconds is", difference
print
print
print "The beginning seconds translate to", begin_struct
print
print "The end seconds translate to", end_struct
print
print
question = raw_input("Do another? (y/n) ")
restart = question.strip()
if (restart == 'y'):
loop = True
elif (restart == 'n'):
loop = False
else:
print "Thank you for using this utility! Press enter to close."
raw_input()