-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib-1681986201-sms.py
More file actions
69 lines (57 loc) · 2.4 KB
/
lib-1681986201-sms.py
File metadata and controls
69 lines (57 loc) · 2.4 KB
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
import tweepy
import json
import time
import datetime
# Authentication details. Enter your own twitter app keys here.
consumer_key = "vYvazxSr4gz19j2UNjQw8W6Fz"
consumer_secret = "QrEoXHQvz7bxKVrniSpEvC89GLDNk0Kua15LpIBYAVhTOtq6Qz"
access_key = "1557317528-L7MMHuKOnC73wbCBLpY9G6JwwounVSHn25aTDRB"
access_secret = "img3XUX9tShwOxBTunHs7wWmvisiTnK0QmUFnOyLHfODc"
# Enter the hashtag you want to search for here.
accountvar = "Pakistan"
# getting the current date and time.
t = datetime.datetime.now()
# sorting the acquired date and time into the format we want as Windows # doesn't allow us to include : in file names.
a = t.strftime('%Y-%m-%d-%H-%M')
# specifying the output file name.
outputfilejson = accountvar+"_"+str(a)+".json"
# This is the listener, resposible for receiving data.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
tweets = tweepy.Cursor(api.search_tweets,
q=accountvar,
count=10,
lang="en",
tweet_mode='extended').items(100)
tweets_list = []
for tweet in tweets:
tweets_list.append({
"id" : tweet.id,
"id_str" : tweet.id_str,
"text" : tweet.full_text,
"source" : tweet.source,
"truncated": tweet.truncated,
"user_tw":
{
"id":tweet.user.id,
"id_str":tweet.user.id_str,
"name":tweet.user.name,
"screen_name":tweet.user.screen_name,
"location":tweet.user.location,
"url":tweet.user.url,
"description":tweet.user.description,
"translator_type":tweet.user.translator_type,
"protected":tweet.user.protected,
"verified":tweet.user.verified,
"followers_count":tweet.user.followers_count,
"friends_count":tweet.user.friends_count,
"listed_count":tweet.user.listed_count,
"favourites_count":tweet.user.favourites_count,
"created_at":str(tweet.user.created_at),
"utc_offset":tweet.user.utc_offset,
"time_zone":tweet.user.time_zone
}
})
with open(outputfilejson, 'w') as fout:
json.dump(tweets_list, fout)