Advertisement
Guest User

Untitled

a guest
May 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # Update: This looks like a far better solution...
  2. # `console.set_idle_timer_disabled(flag)`
  3. # Disable or enable the idle timer (which puts the device to sleep after a certain period of inactivity).
  4.  
  5. # noDoze.py -- keep relaunching yourself to prevent
  6. # your iOS device from falling asleep.
  7.  
  8. import notification, time, urllib
  9.  
  10. def argsString(argv):
  11. if len(argv) < 2: # args for first time thru
  12. argv = [None, 0, "This is only a test..."]
  13. argv[1] = int(argv[1]) + 1
  14. if argv[1] > 15: # stop after 15 lifetimes!
  15. sys.exit()
  16. argStr = ''
  17. for arg in argv[1:]: # ignore argv[0]
  18. argStr += '&' + urllib.urlencode({'argv' : arg})
  19. return argStr
  20.  
  21. def reincarnate(argv): # relaunch self with state in args
  22. (theMessage, theSound) = ('', '') # Silent notification
  23. theDelay = 1 # Just one second of downtime
  24. thisScript = sys.argv[0].rpartition('/')[2].partition('.')[0]
  25. actionURL = 'pythonista://{}?action=run{}'
  26. actionURL = actionURL.format(thisScript, argsString(argv))
  27. returnCode = notification.schedule(theMessage, theDelay,
  28. theSound, actionURL)
  29. #print(returnCode['action_url'])
  30.  
  31. def main(argv):
  32. print('main({}) -- Going to sleep for 30 seconds...'.format(argv[1:]))
  33. time.sleep(30) # Sleep for 30 seconds.
  34. reincarnate(argv) # Silent notification can relaunch self
  35.  
  36. if __name__ == '__main__':
  37. main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement