If not running the Pythonista 3 beta, you can get periodic updates with the code below.
This is not my idea, I just simplified an idea in the TimedRefreshView.py example program, written by cclauss, that I found at:
https://github.com/cclauss/Pythonista_ui/blob/master/TimedRefreshView.py
My program, named "say_random_digit.py", says a random digit from 0 to 9 every 5 seconds.
I had to change the data member "self.update_interval" to "self.updatex_interval" and the method "update" to "updatex" so as not to conflict with the names in the Pythonista 3 beta, which I am currently running.
I like having this functionality built into the ui.View class much more than having to implement it, so I look forward to the beta becoming the released product.
import ui
import threading
import speech
from random import randint
class TimedUpdateView(ui.View):
""" This class contains a method named updatex, which is periodically called. """
def __init__(self):
self.updatex_interval = 5
self.update_after_delay()
def updatex(self):
""" Say a random digit from 0 to 9 every 5 seconds. """
speech.say('%s' % (randint(0, 9)))
def update_after_delay(self):
""" This method calls the updatex method periodically """
self.updatex()
update_thread = threading.Timer(self.updatex_interval,
self.update_after_delay).run()
if __name__ == "__main__":
v = TimedUpdateView()
v.present('sheet')