apscheduler - python - telegram bot sendMessage in specific date -


i terribly new in python , progress snail:( want make telegram bot send message @ specific date , time. used apscheduler , telepot libraries that. , code:

import telepot import sys import time time import sleep datetime import datetime apscheduler.scheduler import scheduler import logging   bot = telepot.bot("***") logging.basicconfig() sched = scheduler() sched.start() exec_date = datetime(2017, 9, 12 ,1,51,0)   def handle(msg):     content_type,chat_type,chat_id = telepot.glance(msg)     print(content_type,chat_type,chat_id)      if content_type == 'text' :         bot.sendmessage(chat_id,msg['text'])   def sendsimpletext(): #     content_type,chat_type,chat_id = telepot.glance(msg) #     print(content_type,chat_type,chat_id) #      #     if content_type == 'text' :     chat_id = telepot.         bot.sendmessage(chat_id,'faez')   def main():     job = sched.add_date_job(sendsimpletext, exec_date)     while true:         sleep(1)         sys.stdout.write('.'); sys.stdout.flush() #     bot.message_loop(handle) # #     job = sched.add_date_job(sendsimpletext, '2017-09-11 21:35:00', ['testfuckbot']) #     while true: #         time.sleep(10)  if __name__ == '__main__':     main() 

my question pass sendsimpletext argument in add_date_job? in line:

job = sched.add_date_job(sendsimpletext, exec_date) 

i know msg message user typed add_date_job have nothing?

you used old (2.1.2) version of apscheduler. new version has new syntax.

a function add_date_job no more available. worked solution you:

import telepot import sys import time datetime import datetime apscheduler.schedulers.background import backgroundscheduler telepot.loop import messageloop import logging  bot = telepot.bot("***your_bot_token***") logging.basicconfig() sched = backgroundscheduler() exec_date = datetime(2017, 9, 12 ,3,5,0)  def handle(msg):     content_type,chat_type,chat_id = telepot.glance(msg)     print(content_type,chat_type,chat_id)      if content_type == 'text' :         bot.sendmessage(chat_id,msg['text'])   def sendsimpletext(chat_id):     bot.sendmessage(chat_id,'faez')   def main():     messageloop(bot, handle).run_as_thread()     job = sched.add_job(sendsimpletext, run_date=exec_date, args=['**your_telegram_id**'])      while true:         time.sleep(1)         sys.stdout.write('.'); sys.stdout.flush()  if __name__ == '__main__':     sched.start()     main() 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -