def get_tweets(api, input_query): tweet in tweepy.cursor(api.search, q=input_query,lang="en").items(): yield tweet if __name__ == "__version__": input_query = sys.argv[1] access_token = "replace_your_key_here" access_token_secret = "replace_your_key_here" consumer_key = "replace_your_key_here" consumer_secret = "replace_your_key_here" auth = tweepy.oauthhandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.api(auth) tweets = get_tweets(api, input_query) tweet in tweets: print(tweet.text)
i trying download data twitter using command prompt. have entered keys (i recreated them all), saved script "print_tweets" , entering "python print_tweets.py subject" command prompt nothing happening, no error message or anything.
i thought problem might have path environment, created program prints out "hello world" , executed without issue using command prompt.
can see obvious errors code above? work you? i've tried changing "version" "main" gives me error message:
if name == "version":
it seems running script in ipython interpreter, won't receiving command line arguments. try this:
import tweepy def get_tweets(api, input_query): tweet in tweepy.cursor(api.search, q=input_query,lang="en").items(): yield tweet input_query = "springbreak" # change string topic want search tweets access_token = "replace_your_key_here" access_token_secret = "replace_your_key_here" consumer_key = "replace_your_key_here" consumer_secret = "replace_your_key_here" auth = tweepy.oauthhandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.api(auth) tweets = get_tweets(api, input_query) tweet in tweets: print(tweet.text)
Comments
Post a Comment