-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtwicli.py
executable file
·82 lines (75 loc) · 3.41 KB
/
twicli.py
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
#!/usr/bin/env python3
import argparse
import tweepy
import json
import sys
from bird import Bird
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check twitter easily')
parser.add_argument('--user', '-u',
help='Get user infos')
parser.add_argument('--tweets', '-t',
help='Download tweets of an user')
parser.add_argument('--tweet', '-T',
help='Download tweet with the given id')
parser.add_argument('--save', '-s',
help='save all infos about an user and their tweets')
parser.add_argument('--file', '-f',
help='File containing usernames, display user infos in CSV format')
args = parser.parse_args()
bird = Bird()
if args.user:
a = bird.get_profile_information(args.user)
print json.dumps(a._json, sort_keys=True, indent=4, separators=(',', ': '))
elif args.tweets:
a = bird.get_user_tweets(args.tweets, limit=1000)
for page in a:
# FIXME : improve this
print json.dumps(page, sort_keys=True, indent=4, separators=(',', ': '))
elif args.tweet:
a = bird.get_tweet(args.tweet)
print json.dumps(a._json, sort_keys=True, indent=4, separators=(',', ': '))
elif args.save:
data = {}
a = bird.get_profile_information(args.save)
data["user"] = a._json
b = bird.get_user_tweets(args.save)
data["tweets"] = []
for t in b:
data["tweets"].append(t._json)
print(json.dumps(data))
elif args.file:
f = open(args.file, 'r')
data = f.read().split()
f.close()
print("Handle;Name;Id;Description;url;Location;Time zone;UTC offset;Created at;Last Tweet;lang;Tweet count;Favourite count;Followers count;Following count;List count;Verified;Geo enabled;Default profile;Default profile image;Contributors Enabled")
for d in data:
try:
user = bird.get_profile_information(d.strip())
print("%s;%s;%i;%s;%s;%s;%s;%i;%s;%s;%s;%i;%i;%i;%i;%i;%s;%s;%s;%s;%s" %
(
user.screen_name,
user.name,
user.id,
user.description.replace(";", ",").replace("\n", ""),
user.entities['url']['urls'][0]['expanded_url'] if user.url is not None else "",
user.location,
user.time_zone,
user.utc_offset if user.utc_offset is not None else 0,
user.created_at.strftime("%m/%d/%Y %H:%M:%S"),
user.status.created_at.strftime("%m/%d/%Y %H:%M:%S") if user.status is not None else "",
user.lang,
user.statuses_count,
user.favourites_count,
user.followers_count,
user.friends_count,
user.listed_count,
user.verified,
user.geo_enabled,
user.default_profile,
user.default_profile_image,
user.contributors_enabled
)
)
except tweepy.error.TweepError:
sys.stderr.write("User %s not found\n" % d.strip())