Python Forum
send repeated messages with apscheduler
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
send repeated messages with apscheduler
#2
When you use fbchat i don't think is running a loop(maybe in bots mode) and just do API call to the chat.
Then you need to make a running loop.
Use BackgroundScheduler so it don't block fbchat calls and your function call is wrong.
Here is a working example.
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime
import time, random

def mesaj_fb(path,my_id):
    print(f'Tick! The time is: {datetime.now()} {random.choice(path), my_id}')

if __name__ == '__main__':
    scheduler = BackgroundScheduler()
    scheduler.add_job(mesaj_fb, 'interval', args=[('image_1.png','image_2.png','image_3.png'), 10], seconds=5)
    scheduler.start()
    print('Press Ctrl+C to exit')
    try:
        while True:
            time.sleep(2)
    except (KeyboardInterrupt, SystemExit):
        scheduler.shutdown()
Output:
C:\code λ python tick.py Press Ctrl+C to exit Tick! The time is: 2020-01-04 21:35:11.823093 ('image_3.png', 10) Tick! The time is: 2020-01-04 21:35:16.823867 ('image_3.png', 10) Tick! The time is: 2020-01-04 21:35:21.823910 ('image_1.png', 10) Tick! The time is: 2020-01-04 21:35:26.824082 ('image_2.png', 10) Tick! The time is: 2020-01-04 21:35:31.824071 ('image_3.png', 10)
Reply


Messages In This Thread
send repeated messages with apscheduler - by pylab - Jan-04-2020, 05:09 PM
RE: send repeated messages with apscheduler - by snippsat - Jan-04-2020, 08:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  User serial/pyserial to send messages to an arudino via terminal manually bkapadia 2 2,752 Mar-10-2021, 11:26 AM
Last Post: Larz60+
  How to tabulate correctly repeated blocks? Xiesxes 4 2,962 Mar-21-2020, 04:57 PM
Last Post: Xiesxes
  How can i use max_instances in apscheduler zebisnaga 0 2,588 Jul-21-2019, 11:17 PM
Last Post: zebisnaga
  logging messages ahead of print messages vindo 6 3,215 Jun-18-2019, 02:45 PM
Last Post: vindo
  Help with apscheduler brakow87 5 6,115 Oct-21-2018, 07:16 PM
Last Post: buran
  create list from repeated pattern in python Code4fun 2 3,445 Sep-25-2018, 07:09 PM
Last Post: woooee
  Parsing Text file having repeated value key pair using python manussnair 3 3,299 Aug-04-2018, 11:48 PM
Last Post: micseydel
  How to convert Schedule to APScheduler module? penguin9 2 3,781 May-03-2018, 12:44 PM
Last Post: penguin9

Forum Jump:

User Panel Messages

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