Created
June 24, 2015 20:24
-
-
Save admiral0/6f7e4dfbe8256dac7b21 to your computer and use it in GitHub Desktop.
telegram_history.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pprint | |
name = "NAME_HERE_USE_UNDERSCORES_FOR_SPACES" | |
QUERY_SIZE = 100 | |
def do_work(msg): | |
pprint.pprint(msg) | |
# Boilerplate. Do not touch | |
import tgl | |
from functools import partial | |
def cb_contact_list(success, peer_list): | |
if success: | |
target = None | |
for peer in peer_list: | |
if name == peer.name: | |
target = peer | |
if target is None: | |
print("PORCODIO NON TROVATO") | |
else: | |
print("Saving history for " + target.name) | |
tgl.get_history(target, 0, QUERY_SIZE, partial(cb_history_recursive, [], target)) | |
else: | |
print("PORCODIO NO") | |
def cb_history_recursive(msg_list, peer, success, msgs): | |
msg_list.extend(msgs) | |
print("Got " + str(len(msgs)) + " messages/Total " + str(len(msg_list))) | |
for msg in msgs: | |
do_work(msg) | |
if len(msgs) == QUERY_SIZE: | |
tgl.get_history(peer,len(msg_list), QUERY_SIZE, partial(cb_history_recursive, msg_list, peer)) | |
print("Getting Contact List") | |
tgl.get_contact_list(cb_contact_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment