Advertisement
Guest User

job persistence not working

a guest
Apr 4th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. # Using picklepersistence-
  2. def test(update, context):
  3.     with open('files/user_data', 'rb') as f:
  4.         context.bot_data['last_sent'] = 'today'
  5.         print(context.bot_data['last_sent'])  # Prints 'today'
  6.         print(pickle.load(f))  # Output is saved and is shown in bot_data
  7.  
  8. dp.add_handler(CommandHandler(command='test', callback=test))
  9. # Above code is run by calling '/test'. bot_data is saved between bot restarts.
  10.  
  11. def test2(context):
  12.     with open('files/user_data', 'rb') as f:
  13.         context.bot_data['last_sent'] = 'today'
  14.         print(context.bot_data['last_sent'])   # Prints 'today'
  15.         print(pickle.load(f))  # 'today' is not saved and its attribute is not printed
  16. updater.job_queue.run_repeating(test2, 86400, first=1)
  17.  
  18. # Above code does not save bot_data between restarts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement