0

I currently run a Twitter bot. I want it to publish an image every ten minutes. I'm currently accomplishing this by using time.sleep(600). This has led it to end up posting things at irregular intervals. However, I'm wanting it to publish an image every ten minutes like clockwork. At 1:00pm, at 1:10pm, at 1:20pm, at 1:30pm, etc. What is the best way to accomplish this?

Gwendolyn97
  • 27
  • 1
  • 6

1 Answers1

3

You should use Cron to execute your script.

*/10 * * * * python your_twitter_script.py

If you want to do it with Python only, sched or schedule are also a solution.

import schedule
import time

def job():
    # twitter job

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
RobinFrcd
  • 4,439
  • 4
  • 25
  • 49