How do I in python to at the end of the code, it go to the beginning again

1

How do I in python to end the code, does it go to the start again and repeat once every 3600 seconds?

My code: *

fb     = Facebook ( "meu-token" )
fb.testing = False

try:
    start_time = time.time()
    markov.collecttext("./markov")
    #markov.collectjsons ("./markov")
    #markov.loadjson("data.json")
    #markov.savejson()
    train_time = time.time() - start_time

    start_time = time.time()
    generated = markov.generate (1)
    generation_time = time.time() - start_time

    if getpyversion() == 2:
        generated = generated.encode('utf8')

    image = randomimg("./images", generated)
    log("Chosen image: " + str(image))

    if not image:
        image = randomimg("./images")
        log("No tags found, randomly chosen image: " + str(image))
        message_start = "Este post foi gerado pelo Marcos Bot\n----------\n"
    else:
        log("tags: " + ", ".join(gettags(generated, image)))
        message_start = "The image was chosen because of the following tag(s): " + ", ".join(gettags(generated, image)) + "\n----------\n"

    response = fb.publish_image ( censor(generated), image )

    log(response)
except Exception as e:
    log("Failed to generate sentence. Posting a random image instead.")
    log(traceback.format_exc(e))
    message = "Failed to generate sent(i)ence. Posting a random image instead:"

    image = randomimg("./images")
    log("Chosen image: " + str(image))

    if not image:
        response = fb.publish_text ( message )
    else:
        response = fb.publish_image ( message, image )

    log(response)

main () *

    
asked by anonymous 14.10.2018 / 12:59

3 answers

1
import threading
def my_function():
  threading.Timer(3600, my_function).start()
  print("Hello, World!")

my_function()

See working at repl.it , I put 5 seconds to see how it works.

    
15.10.2018 / 00:48
1

    
15.10.2018 / 01:54
-1

Another option (not only in python would be to turn this into a recursive function, which calls itself at the end of execution ...

    
15.10.2018 / 01:57