def checktweet(self):
        auth = OAuthHandler(self.twitter_account.consumer_key,
                            self.twitter_account.consumer_secret)
        auth.set_access_token(self.twitter_account.access_token,
                              self.twitter_account.access_secret)
        t_api = tweepy.API(auth)

        self.ensure_one()
        for status in tweepy.Cursor(t_api.home_timeline).items(10):
            if status.text:
                self.twitter_home_feed = status.text

        user = t_api.get_user(self.user_name)
        for friend in user.friends():
            self.twitter_followers_count = friend.screen_name

        for status in tweepy.Cursor(t_api.user_timeline).items(10):
            if status.text:
                self.twitter_timeline_feed = status.text
#
        twitterStream = tweepy.streaming.Stream(auth, tweepy.StreamListener(
        ))  #initialize Stream object with a time out limit
        if self.tw_hashtag:
            tw_stream = twitterStream.filter(track=["#" + self.tw_hashtag],
                                             async=True)  #, languages=['en'].
            self.twitter_stream_filter = tw_stream
Ejemplo n.º 2
0
def main():
 while True:
    try:
	#amiri
		kw=[]		
		kw=readFilelines("~/Desktop/words.txt")
		us=[]		
		us=readFilelines("users")
		print "".join(kw)
		print "".join(us)
		auth = tweepy.OAuthHandler('yPJVzY349RWg2dLU4TCkY8X4t', 'aZHtAjsXX32SHCYecNwYd30MYNm9fcM2PlDvvfXLlfHYPNs49Z') # get consumerkey, consumersecret at https://apps.twitter.com/
		auth.set_access_token('23317561-ec5Hhfip3WIdgUKpweZCoF7O1JTLAp3YjiJaL0gGS', '0cKdULpJbLZMZBj1GdPuTCNUkMKKXOMp3SD0bzwzZ4jDZ') # get accesstoken, accesstokensecret at https://apps.twitter.com/
		api = tweepy.API(auth)
		streamlistener = tweepy.StreamListener(api)
		streamlistener.on_data = my_on_data
		streamlistener.on_error = my_on_error
		stream = tweepy.Stream(auth, listener=streamlistener, secure=True)
		stream.filter(track=kw,follow=us)
		#stream.filter(track=['notonus'])

		#tweetcount = 0
		#filename = gen_file_name()
		
		stream.sample()
    except:
        #f = open(filename + '.unlock', 'w')
        #f.close()
        #filename = gen_file_name()
		print "Unexpected error:", sys.exc_info()[0]
		print "sleeping for a while"
		time.sleep(1)
		continue
 def __init__(self,f_name='twitter.json',output2File=False, couch_user = '******',couch_password = '******',couch_host='127.0.0.1',couch_port=5984,db_name='test',raw_db_name='test', suburbs= None,api=None):
     tweepy.StreamListener(api)
     self.f_name=f_name
     self.output2File=output2File
     self.couch_user=couch_user
     self.couch_password=couch_password
     self.couch_host=couch_host
     self.couch_port=couch_port
     self.db_name=db_name
     self.raw_db_name = raw_db_name
     self.suburbs=suburbs
Ejemplo n.º 4
0
    def listen(self, search_term):
        #Make a listener
        listener = tweepy.StreamListener()
        #Override relevant methods.
        listener.on_status = self.process
        listener.on_error = lambda status_code: self.log("Error: " +
                                                         status_code)
        listener.on_timeout = lambda: self.log("Timeout.")

        twitterStream = tweepy.Stream(auth, listener)
        twitterStream.filter(track=search_term)
Ejemplo n.º 5
0
    def run(self):
        gevent.spawn(self.check_tweets)

        if self.settings.tweet_schedule:
            gevent.spawn(self.tweet_scheduler)

        if self.settings.replies:
            listener = tweepy.StreamListener()
            listener.on_status = self.on_reply
            stream = tweepy.Stream(auth=self.auth, listener=listener)
            gevent.spawn(self.check_replies, stream)

        # Keep main alive
        while True:
            gevent.sleep(1)
Ejemplo n.º 6
0
    def __init__(self, on_status, keyword_manager=StreamKeywordManager()):
        """
        Find statuses on twitter using keyword searches. on_status is called whenever a status is found
        Example:
        >>>def on_status(status):
        >>>    print('Tweet by: @' + status.user.screen_name, "Num of followers:" + str(status.user.followers_count))
        >>>c = Crawler(on_status)

        :param on_status: function to call when a new status is found
        :param keyword_manager: object in charge of supplying keywords to search
        """
        stream_listener = tweepy.StreamListener()
        stream_listener.on_status = on_status

        self.stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
        self.stream.filter(track=keyword_manager.track, follow=keyword_manager.follow,
                           languages=keyword_manager.languages, async=True)
def main():
    consumer_key = "hGbfO8hh7S46tQNp82UQX3Scp"
    consumer_secret = "khksQDEt68pVNanEb1waPokfwJlXMhSKwxKpPPJ2bE050uBESo"

    access_token = "780566626596900865-A0D3MUORh8kH0eu8oVIU8eDno346Jsf"
    access_token_secret = "yxYgyCQtCEPeiwLEmKNz94QrwXaLCE3qfC1mAnqj7tG5A"
    while True:
        try:
            #amiri
            kw = []
            kw = readFilelines("keywords.txt")
            us = []
            us = readFilelines("users")
            print("".join(kw))
            print("".join(us))
            auth = tweepy.OAuthHandler(
                consumer_key, consumer_secret
            )  # get consumerkey, consumersecret at https://apps.twitter.com/
            auth.set_access_token(
                access_token, access_token_secret
            )  # get accesstoken, accesstokensecret at https://apps.twitter.com/
            api = tweepy.API(auth)
            streamlistener = tweepy.StreamListener(api)
            streamlistener.on_data = my_on_data
            streamlistener.on_error = my_on_error
            stream = tweepy.Stream(auth, listener=streamlistener, secure=True)
            stream.filter(track=kw)
            #stream.filter(track=kw,follow=us)
            #stream.filter(track=['notonus'])

            #tweetcount = 0
            #filename = gen_file_name()

            stream.sample()
        except:
            #f = open(filename + '.unlock', 'w')
            #f.close()
            #filename = gen_file_name()
            print("Unexpected error:", sys.exc_info()[0])
            print("sleeping for a while")
            time.sleep(30)
            continue
Ejemplo n.º 8
0
def main():
    while True:
        try:
            #amiri
            kw = []
            kw = readFilelines("keywords")
            us = []
            us = readFilelines("users")
            print "".join(kw)
            print "".join(us)
            auth = tweepy.OAuthHandler(
                'consumerkey', 'consumersecret'
            )  # get consumerkey, consumersecret at https://apps.twitter.com/
            auth.set_access_token(
                'accesstoken', 'accesstokensecret'
            )  # get accesstoken, accesstokensecret at https://apps.twitter.com/
            api = tweepy.API(auth)
            streamlistener = tweepy.StreamListener(api)
            streamlistener.on_data = my_on_data
            streamlistener.on_error = my_on_error
            stream = tweepy.Stream(auth, listener=streamlistener, secure=True)
            stream.filter(track=kw, follow=us)
            #stream.filter(track=['notonus'])

            #tweetcount = 0
            #filename = gen_file_name()

            stream.sample()
        except:
            #f = open(filename + '.unlock', 'w')
            #f.close()
            #filename = gen_file_name()
            print "Unexpected error:", sys.exc_info()[0]
            print "sleeping for a while"
            time.sleep(30)
            continue
Ejemplo n.º 9
0
    #on_status methodunu override ediyoruz
    def on_status(self, status):
        #burada gelen veriyi print ediyoruz
        print(status.text)

    #on_error methodunu override ediyoruz
    def on_error(self, status_code):
        # burada veri dinlerken bir hata alırsak False donduruyoruz
        if status_code == 420:
            return False


#KEY VE TOKENLARI DEGISKENLERE ATIYORUZ AUTHENTICATION ISLEMINDE KULLANIMA HAZIR HALE GETIRMIS OLUYORUZ
cons_key = "CONSUMER_KEY"
sec_key = "SECRET_KEY"
acc_token = "ACCESS_TOKEN"
sec_acc_token = "ACCESS_SECRET_TOKEN"

#tweepy'ın OAuthHandler methodu bizim api'ya baglanmamıza yardım edıyor
auth = tweepy.OAuthHandler(consumer_key=cons_key, consumer_secret=sec_key)
#auth objesıne access token degerımızı set ediyoruz(ayarlıyoruz)
auth.set_access_token(acc_token, sec_acc_token)
#api objesını olusturuyoruz
api = tweepy.API(auth)
#MyStreamListener class'ının objesını olusturuyoruz
myStreamListener = MyStreamListener()
#tweepy kutuphanesının StreamListener Class'ının Constructoruna API nesnesi ve bizim kendi olusturdugumuz class'ın objesını yolluyoruz
myStream = tweepy.StreamListener(auth=api, listener=myStreamListener)
#myStream onjesinin filter methoduna track(takip[filtreleyecegi] edecegi kelime) async=True kısmı ise programın thread kullanarak daha hızlı calısmasını saglıyor
myStream.filter(track=['mertongngl'], async=True)
consumerSecret = 'RWuG21WuPGj4L5RJJqvi2TQnf3pWYq41dDbJL2tk'
accessToken = '26716739-voxrImM5E58OpoCBu74TCelxgvMszvPoJefYkVwJO'
accessTokenSecret = 'fyGrkwWZXCN25K3hkFgEbwxPvMX0UGx5LTR7uAJyiU'

import tweepy

auth1 = tweepy.auth.OAuthHandler(consumerKey, consumerSecret)
auth1.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth1)
#api.update_status('This is a test!') # Will send a Tweet

myFollower = api.followers()[0]
myFollowerInfo = myFollower.__getstate__()

# Read tweets
listener = tweepy.StreamListener()

# SixOhSix twitter module as used by the book Mining the Social Web
import twitter
twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
trends = twitter_api.trends()

import twitter
twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
WORLD_WOE_ID = 1  # The Yahoo! Where On Earth ID for the entire world
world_trends = twitter_api.trends._(WORLD_WOE_ID)  # get back a callable
[trend for trend in world_trends()[0]['trends']]

twitter_search = twitter.Twitter(domain="search.twitter.com")
search_results = []
for page in range(1, 6):
Ejemplo n.º 11
0
 def __init__(self, results):
     tweepy.StreamListener(self)
     self.api = api
     self.results = results
     self.todo = 0