tux_mind

media_saver.py

Aug 2nd, 2015
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import tgl
  2. import pprint
  3. from functools import partial
  4.  
  5. pp = pprint.PrettyPrinter(indent=4)
  6.  
  7. def on_binlog_replay_end():
  8.   tgl.get_contact_list(contact_list_cb)
  9.  
  10. def contact_list_cb(success, peer_list):
  11.   if not success:
  12.     return
  13.   for peer in peer_list:
  14.     if peer.name == "Username":
  15.       peer.history(0, HISTORY_QUERY_SIZE, partial(history_cb, peer))
  16.  
  17. HISTORY_QUERY_SIZE = 100
  18. parsed_count = 0
  19.  
  20. def history_cb(peer, success, msgs):
  21.   global parsed_count
  22.  
  23.   if not success:
  24.     print("ERROR")
  25.     return
  26.  
  27.   #for msg in msgs:
  28.     #if msg.media:
  29.       #msg.load_document(file_cb)
  30.  
  31.   size = len(msgs)
  32.  
  33.   parsed_count += size
  34.  
  35.   print("parsed %d messages" % parsed_count)
  36.  
  37.   if size == HISTORY_QUERY_SIZE:
  38.     peer.history(parsed_count, HISTORY_QUERY_SIZE, partial(history_cb, peer));
  39.    
  40. def file_cb(success, path):
  41.   if success:
  42.     print(path)
  43.  
  44. def on_secret_chat_update(peer, types):
  45.   pass
  46.  
  47. def on_user_update(a, b):
  48.   pass
  49.  
  50. def on_chat_update(a, b):
  51.   pass
  52.  
  53. def on_msg_receive(msg):
  54.   pass
  55.  
  56. def on_get_difference_end():
  57.   pass
  58.  
  59. def on_our_id(id):
  60.   pass
  61.  
  62. tgl.set_on_binlog_replay_end(on_binlog_replay_end)
  63. tgl.set_on_get_difference_end(on_get_difference_end)
  64. tgl.set_on_our_id(on_our_id)
  65. tgl.set_on_msg_receive(on_msg_receive)
  66. tgl.set_on_secret_chat_update(on_secret_chat_update)
  67. tgl.set_on_user_update(on_user_update)
  68. tgl.set_on_chat_update(on_chat_update)
Advertisement
Add Comment
Please, Sign In to add comment