Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- save_path = '/storage/sdcard0/a.txt'
- def get_time (seconds):
- if seconds > 0:
- if seconds <= 60:
- return str (seconds) + " seconds"
- elif seconds > 60 and seconds < 3600:
- return str ((seconds) / 60) + " minutes"
- elif seconds > 3600 and seconds < 86400:
- return str ((seconds) / 3600) + " hours"
- elif seconds > 86400:
- return str ((seconds) / 86400) + " days"
- else:
- raise ValueError ("Bad Number")
- lasttime = 0.0
- with open (save_path, mode = 'a', encoding = 'utf-8') as checkfile:
- #Create file if it doesnt already exist
- checkfile.write ("")
- with open (save_path, mode = 'r+', encoding = 'utf-8') as readfile:
- #Read old time
- temp = readfile.read ()
- if temp:
- lasttime = temp
- else:
- print ("Save file is empty")
- lasttime = float (lasttime)
- print ("Its been", get_time (time () - lasttime))
- saveq = input ("Overwrite time? (y / n)\n")
- if saveq.lower () == 'y':
- with open (save_path, mode = 'w+', encoding = 'utf-8') as writefile:
- #Save new time if the user wants
- writefile.write (str (time ()))
- print ("Saved", end = ", ")
- print ("Goodbye")
Advertisement
Add Comment
Please, Sign In to add comment