Marcus
Marcus

Reputation: 9

Obtain tweets with hashtags in them - Teepy

I have a basic program working using the Tweepy API. It essentially grabs tweets from a user and outputs it to a terminal. Ideally, I'd like this to be automated, so when the user tweets, the program will see it and display the tweet. But that's a question for another time.

What I'd like to do now, however, is grab the tweets with only a hashtag in it.

How do I go about this? I'm hoping it's a parameter I can add with inside the timeline function..?

Here is a snippet of the code I have at the moment:

import tweepy
import twitter_credentials

auth = tweepy.OAuthHandler(twitter_credentials.CONSUMER_KEY, twitter_credentials.CONSUMER_SECRET)
auth.set_access_token(twitter_credentials.ACCESS_TOKEN, twitter_credentials.ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

stuff = api.user_timeline(screen_name = 'XXXXXX', count = 10, include_rts = False)

for status in stuff:
    print(status.text)

Upvotes: 0

Views: 229

Answers (1)

ankur09011
ankur09011

Reputation: 473

For a simple use case you can use # in the search string, for example:

api = tweepy.API(auth,wait_on_rate_limit=True)

tweet in tweepy.Cursor(api.search,q="#",count=100).items():
    print(tweet)

This will give you tweets which contain any hastags.

Upvotes: 1

Related Questions