Python Forum
How to convert Schedule to APScheduler module?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert Schedule to APScheduler module?
#1
I'm a python newbie and need a little help with my code.

I need to convert my code to use APSCHEDULER and not SCHEDULE module because I need to use hours, minutes, seconds which SCHEDULE is not capable of. How can I convert this script to use hh:mm:ss ?

Note: I did read the apscheduler documentation and examples, and oddly enough there isn't anything about scheduling a job to run at exactly 7:45:30 PM. All the examples appeared to be geared towards cron jobs running every seconds=3.

Here is my code for schedule-module
import subprocess
import time
import schedule


def job1():

    subprocess.call("netsh interface portproxy add v4tov4 listenaddress=192.168.0.153 listenport=1101 connectaddress=192.168.0.153 connectport=809 protocol=tcp", shell=True)


def job2():

    subprocess.call("netsh interface portproxy reset", shell=True)


schedule.every().day.at("06:00").do(job1)

schedule.every().day.at("07:00").do(job2)
Reply
#2
Probably you already visited this site: https://apscheduler.readthedocs.io/en/la.../cron.html
on the bottom you will find an example using minutes.
import subprocess
from apscheduler.schedulers.background import BackgroundScheduler
 
def job1():
 
    subprocess.call("netsh interface portproxy add v4tov4 listenaddress=192.168.0.153 listenport=1101 connectaddress=192.168.0.153 connectport=809 protocol=tcp", shell=True)
 
 
def job2():
 
    subprocess.call("netsh interface portproxy reset", shell=True)

schedule1 = BackgroundScheduler()
schedule2 = BackgroundScheduler()
schedule1.add_job(job1, 'cron', hour='06', minute='00', second='00')
schedule2.add_job(job2, 'cron', hour='07', minute='00', second='00')
schedule1.start()
schedule2.start()
there you can define seconds and days, etc. :)
Reply
#3
Wow! I'm going to try that! Thank you so much! Been hitting my head against a wall for half a day.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cancelling previous schedule cosmarchy 2 2,783 Sep-15-2021, 04:55 PM
Last Post: Larz60+
  Hosting a script on a VPS, and on a schedule? oldguy 0 2,944 Mar-13-2021, 02:46 AM
Last Post: oldguy
  send repeated messages with apscheduler pylab 1 1,898 Jan-04-2020, 08:43 PM
Last Post: snippsat
  something i noticed about the "schedule" module Stan2292 1 1,765 Aug-30-2019, 06:04 AM
Last Post: buran
  How can i use max_instances in apscheduler zebisnaga 0 2,573 Jul-21-2019, 11:17 PM
Last Post: zebisnaga
  How to schedule Jupyter Notebooks with Papermill wendysling 0 2,499 Jun-11-2019, 05:53 PM
Last Post: wendysling
  schedule module conundrum wgovideo 11 4,314 May-29-2019, 06:39 PM
Last Post: wgovideo
  Is there any way to convert a python script (with Tkinter module), to a .exe (Windows moste 3 4,000 May-12-2019, 12:02 PM
Last Post: snippsat
  Not able to convert PYWINAUTO module automation in exe file Utkarsh29 0 2,440 Mar-19-2019, 09:39 PM
Last Post: Utkarsh29
  Help with apscheduler brakow87 5 6,087 Oct-21-2018, 07:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020