Created
April 30, 2015 12:54
-
-
Save scturtle/d61422cc69f4a2f6e0b5 to your computer and use it in GitHub Desktop.
get key and secret via tweetdeck
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
import sys | |
import requests | |
from pprint import pprint | |
from base64 import encodestring | |
from rauth import OAuth1Session | |
assert len(sys.argv) == 3, "Useage: python twlogin.py USERNAME PASSWORD" | |
headers = { 'authorization': 'x-td-basic ' + encodestring(sys.argv[1] + ':' + sys.argv[2]), | |
'X-TD-Authtype': 'twitter' } | |
data = requests.get('https://tweetdeck.twitter.com/login', headers=headers).json() | |
assert 'session' in data, "error:" + str(data) | |
#pprint(data) | |
headers = { 'Authorization': 'X-TD-Session ' + data['session'] } | |
data = requests.get('https://tweetdeck.twitter.com/accounts', headers=headers).json() | |
assert 'key' in data[0], "error:" + str(data) | |
#pprint(data) | |
session = OAuth1Session(consumer_key="yT577ApRtZw51q4NPMPPOQ", | |
consumer_secret="3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8", | |
access_token=data[0]['key'], | |
access_token_secret=data[0]['secret']) | |
data = session.get('https://api.twitter.com/1.1/activity/by_friends.json').json() | |
get_name = lambda u: '@'+u['screen_name'] | |
join_name = lambda us: ', '.join(map(get_name, us)) | |
for i in data: | |
print join_name(i['sources']), i['action'], ':' | |
if i['action'] == 'favorite': | |
for t in i['targets']: | |
print ' ', get_name(t['user'])+':', t['text'].encode('utf8') | |
elif i['action'] == 'follow': | |
print ' ', join_name(i['targets']) | |
else: | |
raise Exception('unkown action') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment