Last active
May 13, 2019 01:59
-
-
Save NISH1001/e8f6e6b37067a3e7ae1369e78e859723 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from tweepy.streaming import StreamListener | |
from tweepy import OAuthHandler | |
from tweepy import Stream | |
import tweepy | |
import sys | |
class StdOutListener(StreamListener): | |
def on_data(self,data): | |
print(data) | |
return True | |
def on_error(self, status): | |
print(status) | |
def main(): | |
access_token = "something" | |
access_token_scret = "something" | |
consumer_key = "something" | |
consumer_secret = "something" | |
hashtag = sys.argv[1::] # or any hard-coded string | |
if len(hashtag) > 0: | |
listener = StdOutListener() | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_scret) | |
""" | |
stream = Stream(auth, listener) | |
stream.filter(track=['python']) | |
""" | |
api = tweepy.API(auth) | |
""" | |
public_tweets = api.home_timeline() | |
for tweet in public_tweets: | |
if "python" in tweet.text: | |
print(tweet.text) | |
""" | |
query = "#" + hashtag[0] | |
print(query) | |
cursor = tweepy.Cursor(api.search, q=query) | |
count = 0 | |
for item in cursor.items(): | |
count += 1 | |
print("Tweet count : {} ".format(count)) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment