Last active
August 29, 2015 14:01
-
-
Save brianly/dffc4098805815d6c2d6 to your computer and use it in GitHub Desktop.
Iterate over the /api/v1/messages/sent.json endpoint and just return those for your user. Takes your user ID as input (can be automated.)
This file contains hidden or 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
import sys | |
import time | |
import yampy | |
import webbrowser | |
def get_input(prompt): | |
if sys.hexversion > 0x03000000: | |
return input(prompt) | |
else: | |
return raw_input(prompt) | |
def list_sent_messages(token, from_id, count=0): | |
yammer = yampy.Yammer(access_token=token) | |
message_id = None | |
while True: | |
sent_messages = yammer.messages.sent(older_than=message_id) | |
for message in sent_messages.messages: | |
if message['sender_id'] == from_id: | |
print message['id'] | |
print message['url'] | |
print message['created_at'] | |
print message['body']['plain'] | |
print '----------------------------------------------' | |
last_item = sent_messages.messages[-1] | |
message_id = last_item['id'] | |
time.sleep(15) | |
count += 1 | |
if count == 20: | |
break | |
print('done') | |
def authorize(): | |
authenticator = yampy.Authenticator(client_id='', | |
client_secret='') | |
redirect_uri = 'https://www.bing.com/' | |
auth_url = authenticator.authorization_url(redirect_uri) | |
webbrowser.open(auth_url) | |
code = get_input('Enter the code: ') | |
return authenticator.fetch_access_token(code) | |
if __name__ == "__main__": | |
# token = authorize() | |
# print token | |
token = '' | |
list_sent_messages(token, 123456) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment