如何使用Tweepy Cursor api.search将推文信息保存到有序的JSON中?

时间:2016-02-25 14:10:47

标签: python json tweepy

我想以JSON格式保存推文信息,如下所示:

{
    "created_at":
    "id":
    "id_str":
    "text":
.
.
.
etc

[更新]它适用于此代码。好极了!它最终保存所有推文信息。但是还有另一个问题,它是无序的,我想要上面的顺序,而不是字母顺序

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import tweepy
import time

ckey ='x'
csecret = 'x'
atoken = 'x'
asecret ='x'

auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

api = tweepy.API(auth)

for tweet in tweepy.Cursor(api.search,geocode="-   6.1750,106.8283,438.37km",since='2016-02-18',until='2016-02-24').items():
    with open('dataJakarta2.json', 'a') as f:
        for abc in tweet.entities.get("urls",[{}]):
            if "swarmapp.com" not in abc.get("expanded_url",None):
                continue
            else:
               f.write(json.dumps(tweet._json))
               f.write("\n")

0 个答案:

没有答案