-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.py
61 lines (44 loc) · 1.73 KB
/
json.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
import json
import os
from datetime import datetime
from time import sleep
import pandas as pd
from requests_oauthlib import OAuth1Session
def gettweet(keyword)
CK = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
CS = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
AT = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ATS = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
twitter = OAuth1Session(CK, CS, AT, ATS)
max_id = -1
url = "https://api.twitter.com/1.1/search/tweets.json"
params = {'q' : keyword, 'count' : 100, 'max_id': max_id, 'since_id': since_id}
tweets = {}
for i, tweet in enumerate(tweets):
if i >= max_id:
break
if max_id != -1:
params['max_id'] = max_id
req = twitter.get(url, params = params)
if req.status_code ==200:
tweets = json.loads(req.text)
if tweets['statuses'] ==[]:
break
for tweet in tweets["statuses"]:
tweet_id = int(tweet["id_str"])
name_id = tweet["screenname"]
twitter_name = tweet["name"]
tweet_contents = tweet["full_text"]
tweet_profile = tweet["description"]
follower = tweet["follower"]
dt = datetime.strptime(tweets['created_at'],'%a %b %d %H:%M:%S %z %Y')
dt = dt.astimezone()
dst = datetime.strftime(dt, '%Y-%m-%d %H:%M:%S')
favorite_count = tweet["favoriet_count"]
quoted = tweet["is_quate_status"]
retweet = tweet["retweet_count"]
mention = tweet["usermention"]
max_id = tweets['statuses'][-1]['id']
else:
print('15分待ってね!')
sleep(15*60)