python - Retrieve specific number of tweets using search keyword -


from tweepy import stream tweepy import oauthhandler tweepy.streaming import streamlistener import time   s=raw_input('string');  try:     file = open('keyword.txt', 'r')     keyword=file.read()       ckey ='consumer key'     csecret ='consumer secret'     atoken ='access token'     asecret='access secret'      class listener(streamlistener):          def on_data(self, data):              # print data              tweet=data.split(',"text":"')[1].split('","source')[0]             print (tweet)             print ('\n')             savethis=tweet             savefile =open('projectdatabase.csv','a')             savefile.write(savethis )             savefile.write('\n')             savefile.close()             return true          def on_error(self, status):             print (status)               auth=oauthhandler(ckey, csecret)             auth.set_access_token(atoken, asecret)             twitterstream=stream(auth, listener())             twitterstream.filter(track=[keyword])  except exception: 

your question needs more descriptive,however if want obtain specific number of tweets using search...you can refer example

import tweepy import csv #import csv import json import codecs import datetime

from tweepy.streaming import streamlistener tweepy import oauthhandler tweepy import stream  #access tokens  auth = tweepy.auth.oauthhandler('#######', '#######') auth.set_access_token('########', '######')  api = tweepy.api(auth) # open/create file append data csvfile = open('result1234.csv', 'a') #use csv writer csvwriter = csv.writer(csvfile) f = codecs.open('abc.csv',encoding='utf-8', mode='a')  tweet in tweepy.cursor(api.search,                      q="interstellar",                      since="2015-01-30",                      until="2015-02-01",                   lang="en").items(10000): #write row csv file/ use encode utf-8 print tweet; csvwriter.writerow([tweet]) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -