Python/schedule: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:
schedule.every().wednesday.at('02:56:00').at('02:56:30').do(job)
schedule.every().wednesday.at('02:56:00').at('02:56:30').do(job)
</source>
</source>
== standard ==


<source lang="python">
<source lang="python">
Line 31: Line 33:
18:38:06 | I'm working.
18:38:06 | I'm working.
18:38:09 | I'm working.
18:38:09 | I'm working.
</source>
== long time job ==
<source lang="python">
import datetime
import time
import schedule
def job():
  isotime = datetime.datetime.now().strftime('%H:%M:%S')
  print("{} | I'm working.".format(isotime))
  time.sleep(2)
schedule.every(3).seconds.do(job)
while True:
  schedule.run_pending()
  time.sleep(1)
</source>
<source lang="text">
18:40:16 | I'm working.
18:40:21 | I'm working.
18:40:26 | I'm working.
18:40:31 | I'm working.
18:40:36 | I'm working.
</source>
</source>

Revision as of 10:41, 23 December 2020

Some tests

# Okay
schedule.every().wednesday.at('02:28').do(job)
# No effect
schedule.every().wednesday.thursday.at('02:28').do(job)
# 02:56:30 works only
schedule.every().wednesday.at('02:56:00').at('02:56:30').do(job)

standard

import datetime
import time
import schedule

def job():
  isotime = datetime.datetime.now().strftime('%H:%M:%S')
  print("{} | I'm working.".format(isotime))

schedule.every(3).seconds.do(job)
while True:
  schedule.run_pending()
  time.sleep(1)
18:37:57 | I'm working.
18:38:00 | I'm working.
18:38:03 | I'm working.
18:38:06 | I'm working.
18:38:09 | I'm working.

long time job

import datetime
import time
import schedule

def job():
  isotime = datetime.datetime.now().strftime('%H:%M:%S')
  print("{} | I'm working.".format(isotime))
  time.sleep(2)

schedule.every(3).seconds.do(job)
while True:
  schedule.run_pending()
  time.sleep(1)
18:40:16 | I'm working.
18:40:21 | I'm working.
18:40:26 | I'm working.
18:40:31 | I'm working.
18:40:36 | I'm working.