exampletwit.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:twittershade 作者: nicolavic98 项目源码 文件源码
def Query():
    QUERY = 'big'
    # The file to write output as newline-delimited JSON documents
    OUT_FILE = QUERY + ".json"

    # Authenticate to Twitter with OAuth

    auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
                               CONSUMER_KEY, CONSUMER_SECRET)

    # Create a connection to the Streaming API

    twitter_stream = twitter.TwitterStream(auth=auth)


    print 'Filtering the public timeline for "{0}"'.format(QUERY)

    # See https://dev.twitter.com/docs/streaming-apis on keyword parameters

    stream = twitter_stream.statuses.filter(track=QUERY)

    # Write one tweet per line as a JSON document.

    with io.open(OUT_FILE, 'w', encoding='utf-8', buffering=1) as f:
        for tweet in stream:
            f.write(unicode(u'{0}\n'.format(json.dumps(tweet, ensure_ascii=False))))
            print tweet['text']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号