/
find_user
executable file
·83 lines (64 loc) · 1.84 KB
/
find_user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env python
from __future__ import absolute_import, print_function
import sys
if len(sys.argv) < 2:
print("find_user: missing user id")
exit()
else:
user = sys.argv[1]
import couchdb
import pprint
pp = pprint.PrettyPrinter(indent=4)
s=couchdb.Server()
db=s['twitter']
u=db.get(user)
if u:
pp.pprint(dict(u))
exit()
result=db.view('lookups/screen_name', wrapper=None)
for u in result[user.lower()]:
pp.pprint(dict(db[u.id]))
exit()
import tweepy
import time
import yaml
import os
import requests
import json
stream = open( os.path.expanduser('~') + "/.twittercl.yaml", "r")
keys = yaml.load(stream)
consumer_key=keys['consumer_key']
consumer_secret=keys['consumer_secret']
passcode = keys['passcode']
def warning(*objs):
print("WARNING: ", *objs, file=sys.stderr)
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.secure = True
access = json.loads(requests.get("http://bea-en-dee.ryanjyoder.com/get_tokens.php?c=" + passcode).content)
access_token=access['oauth_token']
access_token_secret=access['oauth_token_secret']
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# If the authentication was successful, you should
# see the name of the account print out
result = 0
while result == 0:
try:
result = api.get_user(user)
except tweepy.RateLimitError:
warning("Rate limit exhausted. sleeping...")
time.sleep(10)
access = json.loads(requests.get("http://bea-en-dee.ryanjyoder.com/get_tokens.php?c=" + passcode).content)
access_token=access['oauth_token']
access_token_secret=access['oauth_token_secret']
auth.set_access_token(access_token, access_token_secret)
j = result._json
j['type'] = 'user'
j['_id'] = j['id_str']
db.save(j)
if len(sys.argv) < 3:
pp.pprint(result._json)
else:
for i in range(2,len(sys.argv)):
print( str(result._json[sys.argv[i]]) + "\t", end="")
print()