Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy
- import json
- ACCESS_TOKEN = '171306628-rm6BL9ZPxUNkVnQLVwXzzYTFuVaJaEon7b6wBUTe'
- ACCESS_SECRET = 'xMZD6fjmjsExcAcP7dBl9JqNKwaLlgIrcGytrjndw4LOZ'
- CONSUMER_KEY = 'BbOdUxMrFDZwxpoNLrExchkrx'
- CONSUMER_SECRET = 't2RLTNaT8lUzjBgxIhii53jBO5I9mkhEfsK72HlR8ZT3spRoWf'
- def connect_to_twitter_OAuth():
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
- api = tweepy.API(auth)
- return api
- api = connect_to_twitter_OAuth()
- class MyStreamListener(tweepy.StreamListener):
- def on_data(self, data):
- try:
- with open('python, json', 'a') as f:
- f.write(data)
- return True
- except BaseException as e:
- print('Error on_data: %s'% str(e))
- return True
- def on_error(self,status):
- print(status)
- return True
- myStreamListener = MyStreamListener()
- twitter_stream = tweepy.Stream(auth = api.auth, listener = myStreamListener)
- twitter_stream.filter(track=['#Senin'])
- #public_tweets = api.home_timeline()
- #for tweet in public_tweets:
- # print(tweet.text)
- #for status in tweepy.Cursor(api.home_timeline).items(5):
- # print(status.text)
- #for friend in tweepy.Cursor(api.friends).items():
- # print(friend.name)
- #for tweet in tweepy.Cursor(api.user_timeline).items(10):
- # print(tweet.text)
- #detik_tweets = api.user_timeline('detikcom')
- #for tweet in detik_tweets:
- # print(tweet.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement