forked from DocNow/twarc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.py
executable file
·34 lines (28 loc) · 1.17 KB
/
tweet.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
#!/usr/bin/env python
"""
Fetch a single tweet as JSON using its id.
"""
from __future__ import print_function
import os
import json
import twarc
import argparse
e = os.environ.get
parser = argparse.ArgumentParser("tweet.py")
parser.add_argument('tweet_id', action="store", help="Tweet ID")
parser.add_argument("--consumer_key", action="store",
default=e('CONSUMER_KEY'),
help="Twitter API consumer key")
parser.add_argument("--consumer_secret", action="store",
default=e('CONSUMER_SECRET'),
help="Twitter API consumer secret")
parser.add_argument("--access_token", action="store",
default=e('ACCESS_TOKEN'),
help="Twitter API access key")
parser.add_argument("--access_token_secret", action="store",
default=e('ACCESS_TOKEN_SECRET'),
help="Twitter API access token secret")
args = parser.parse_args()
tw = twarc.Twarc(args.consumer_key, args.consumer_secret, args.access_token, args.access_token_secret)
tweet = tw.get('https://api.twitter.com/1.1/statuses/show/%s.json' % args.tweet_id)
print(json.dumps(tweet.json(), indent=2))