def start_stream(term=None, lang=None, locs=None): stream = None try: if term and lang: listen = SListener(api, term=term, lang=lang) stream = tweepy.Stream(auth, listen) stream.filter(languages=[lang], track=[term[0]]) elif locs: listen = SListener(api, loc=locs) stream = tweepy.Stream(auth, listen) stream.filter(locations=locs[:-1]) except: print("error!") stream.disconnect()
def main(): es = Elasticsearch(hosts=[endpoint], port=443, use_ssl=True, verify_certs=True, ca_certs=certifi.where()) myStreamListener = SListener(es) auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) myStream = tweepy.Stream(auth, myStreamListener) myStream.filter(track=["Job", "Happy", "Movie", "Show", "Drink", "Food", "Beautiful", "Trip", "Columbia", "New York"], async=True)
def main(): # streaming data from table appID = 1 batch_nm = 3 location = 'australia' database = 'twitter_tasmania' table = 'twitter_data_tasmania' # prefix = 'aus_loc_tas_users_batch'+'_'+str(batch_nm) prefix = 'commbank_mention_' datetime = time.strftime('%Y%m%d-%H%M%S') print("Using authcode from app {} and batch {}".format(appID, batch_nm)) # OAuth process, using the keys and tokens from app lpy531 and batch 1 authcode = AC.AuthCode(appID, batch_nm) auth = tweepy.OAuthHandler(authcode.consumer_key, authcode.consumer_secret) auth.set_access_token(authcode.access_key, authcode.access_secret) api = tweepy.API(auth) listen = SListener(api, prefix, location) stream = tweepy.Stream(auth, listen) # follow_set = get_userID(database, table, batch_nm) print( "Streaming for tweets posted from Australia, and by users in tasmania, batch {}" .format(batch_nm)) try: # stream.filter(follow= follow_set, async= True, locations=[108.883637, -43.689318, 154.500308, -10.143083]) # stream.filter(follow=follow_set, async=True) stream.filter(track=['cba'], async=True) #stream.sample() except: print("error!") stream.disconnect()
def main(argv): try: opts, args = getopt.getopt(argv, "h:kj", ["help", "key=" ]) except getopt.GetoptError: sys.exit(2) for opt, arg in opts: if opt in ("-h", "help"): sys.exit() elif opt == '-k': auth = tweepy.OAuthHandler(twitterDevKeys.consumer_key, twitterDevKeys.consumer_secret) auth.set_access_token(twitterDevKeys.access_token, twitterDevKeys.access_token_secret) print "Accessing with %s key" % (twitterDevKeys.access_token) key = 1 elif opt == '-j': auth = tweepy.OAuthHandler(twitterDevKeys.consumer_key2, twitterDevKeys.consumer_secret2) auth.set_access_token(twitterDevKeys.access_token2, twitterDevKeys.access_token_secret2) print "Accessing with %s key" % (twitterDevKeys.access_token2) key = 2 else: auth = tweepy.OAuthHandler(twitterDevKeys.consumer_key, twitterDevKeys.consumer_secret) auth.set_access_token(twitterDevKeys.access_token, twitterDevKeys.access_token_secret) print "Accessing with %s key" % (twitterDevKeys.access_token) key = 1 api = tweepy.API(auth) if key == 1: track = ['AAPL', 'apple', 'mac', 'tim cook', 'GOOG', 'google', 'gmail', 'youtube'] elif key == 2: track = ['twitter', 'tweet', 'twtr', 'amazon', 'amzn', 'prime', 'aws' ] follow = [] listen = SListener(api, 'stocktweets') stream = tweepy.Stream(auth, listen) print "Streaming started on %s keywords " % (len(track)) print track # while True: try: # captureTweets(listen, track) if key == 1: stream.filter(track=[ 'AAPL', 'apple', 'mac', 'tim cook', 'goog', 'google', 'gmail', 'youtube'], follow) elif key == 2: stream.filter(track=['twitter', 'twtr', 'amazon', 'amzn', 'prime','aws'], follow) except tweepy.TweepError as e: rate_info = api.rate_limit_status()['resources'] reset_time = rate_info print e.message
def main(): tracks = ["StrangerThings", "Stranger_Things"] twitter_stream = tweepy.Stream(auth, SListener()) print("Streaming started...") try: #twitter_stream.filter(track=tracks, locations=GTA, async=True) # does not accept two filters simultaneously twitter_stream.filter(locations=NA, async=True) except: print("error!") twitter_stream.disconnect()
def main(): track = ['obama', 'romney'] listen = SListener(api, 'streamer') stream = tweepy.Stream(auth, listen) boundingBox = [-180, -90, 180, 90] print "Streaming started..." # try: stream.filter(locations=boundingBox)
def collect_twitter_data(keywords_to_track, n, outfilename): """Collect tweets through Twitter API Arguments: keywords_to_track {tuple} -- tuple of keywords n {integer} -- number of tweets per harvest outfilename {string} -- name of output file """ # ============================================================================= # CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, and ACCESS_SECRET are assigned by Twitter # ============================================================================= # Consume: CONSUMER_KEY = 'JwwT7m1VDOBAE8B6GtVByJGQc' CONSUMER_SECRET = 'CZZapYECTEJfwa7k1Q1Bc78l7s1l70Z2a1LeURNmzv9V87B6Nw' ACCESS_TOKEN = '2807778672-2fCpNEvs7V0Rlg7JAeJDPLzNGmpj72qclulmdr4' ACCESS_SECRET = 'leP205x262bbTgKqdVjJQbTzdO8wwBRs4sbMrT1jN9WSr' # Consumer key authentication auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) # Access key authentication auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET) # Set up the API with the authentication handler api = tweepy.API(auth) api.sleep_on_rate_limit = True # Instantiate the SListener object listen = SListener(api) # Instantiate the Stream object stream = tweepy.Stream(auth, listen) # Begin collecting data tweet_data = tweepy.Cursor(api.search, q=keywords_to_track, languages=["en"]).items(n) # Export tweets to file script_dir = os.path.dirname(__file__) rel_path = "twitter_data/" + outfilename abs_file_path = os.path.join(script_dir, rel_path) ctr = 0 with open(abs_file_path, 'w') as outfile: outfile.write('[') for tweet in tweet_data: ctr = ctr + 1 if ctr != 1: outfile.write(',') json.dump(tweet._json, outfile) outfile.write(']') outfile.close()
def main(): track = ['hillary', 'clinton', 'trump', 'donald', 'election2016'] languages = ["en"] listen = SListener(api, 'Twitter.Elections.Data') stream = tweepy.Stream(auth=api.auth, listener=listen) print "Streaming started..." # try: stream.filter(languages=languages, track=track)
def main(): track = ['obama', 'romney'] listen = SListener(api, 'myprefix') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track=track) except: print "error!" stream.disconnect()
def main(): track = ['hillary clinton', 'bernie sanders', 'donald trump'] listen = SListener(api, 'myprefix') stream = tweepy.Stream(auth, listen) print("Streaming started...") try: stream.filter(track=track) except: print("error!") stream.disconnect()
def main(): track = ['#TolakPartaiPoligami'] listen = SListener(api, 'TolakPartaiPoligami') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track=track) except: print "error!" stream.disconnect()
def main(): track = ['The Shallows'] listen = SListener(api, 'movie_data') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track = track, languages=["en"]) except Exception as e: print traceback.print_exc() stream.disconnect()
def main(): listen = SListener(api, 'FILE2') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: ### Track tweets for foloowing hastags ### stream.filter(track=[ '#TakeAKnee', '#TakeAKneeNFL', '#TakeTheKnee', '#boycottnfl' ]) except: print "error!" stream.disconnect()
def main(): tracks = ['machinelearning', 'machine learning', 'bigdata'] prefix = '_'.join(tracks) listen = SListener(api, prefix) stream = tweepy.Stream(auth, listen) print "Streaming started..." print tracks try: stream.filter(track=tracks) except: print "error!" print stream.status_code stream.disconnect()
def main(): track = ['#P2CSC555F15'] listen = SListener(api, 'myprefix') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track=track) print "stream: " except: print "error!" stream.disconnect() print "DONE"
def main(): track = ['erlespider'] listen = SListener(api, 'erle') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track = track) #stream.filter() except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) stream.disconnect()
def main(argv): ## auth. ## Eventually you'll need to use OAuth. Here's the code for it here. ## You can learn more about OAuth here: https://dev.twitter.com/docs/auth/oauth ## Get this from twitter: I left the comments blank to be filled in with your information consumer_key = '' consumer_secret = '' access_token = '' access_token_secret = '' # OAuth process, using the keys and tokens auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) name = 'default' maxTweets = 35 track = [name] follow = [] try: opts, args = getopt.getopt(argv, "hk:m:", ['keyword', 'maxtweets']) except getopt.GetoptError: print 'streaming2.py -k <keyword> -m <maxtweets>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'datacount.py -k <keyword> -m <maxtweets>' sys.exit() elif opt in ("-k", "--keyword"): name = arg track = [name] elif opt in ("-m", "--maxtweets"): maxTweets = arg print(name) print(maxTweets) listen = SListener(api, name, maxTweets) stream = tweepy.Stream(auth, listen) print "Streaming started on %s users and %s keywords..." % (len(track), len(follow)) try: stream.filter(track=track, follow=follow) #stream.sample() except: stream.disconnect()
def main(): track = [ 'southpaw', 'black mass', 'blackmass', 'maze runner', 'mazerunner' ] listen = SListener(api, 'movie_data') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track=track, languages=["en"]) except: print "error!" stream.disconnect()
def main( mode = 1 ): track = ['oil'] follow = [] listen = SListener(api, 'test') stream = tweepy.Stream(auth, listen) print "Streaming started on %s users and %s keywords..." % (len(track), len(follow)) try: stream.filter(track = track, follow = follow) #stream.sample() except: print "error!" stream.disconnect()
def main(): track = [ '#iPhoneX', '#iPhone10', 'iPhoneX', 'iPhone10', 'iPhone X', 'iPhone 10' ] #track = ['and','the'] listen = SListener(api, 'user_data') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(track=track) except: print "error!" stream.disconnect()
def main(): # track = ['dundundundun'] full = [-180, -90, 180, 90] rutgers = [-74.496245, -40.464329, -74.374364, 40.540052] nj = [-76, 38.5, -73.5, 41.5] listen = SListener(api, 'data') stream = tweepy.Stream(auth, listen) #import requests.packages.urllib3 #requests.packages.urllib3.disable_warnings('SNIMissingWarning') #requests.packages.urllib3.disable_warnings('InsecurePlatformWarning') #try: stream.filter(locations=nj) print("Streaming started...")
def main(): if None in [os.getenv( 'CONSUMER_KEY' ), os.getenv( 'CONSUMER_SECRET' ), os.getenv( 'APPLICATION_KEY'), os.getenv( 'APPLICATION_SECRET') ]: print >> sys.stderr, 'Missing auth tokens' sys.exit(1) auth = tweepy.OAuthHandler( os.getenv( 'CONSUMER_KEY' ), os.getenv( 'CONSUMER_SECRET' ) ) auth.set_access_token( os.getenv( 'APPLICATION_KEY'), os.getenv( 'APPLICATION_SECRET') ) api = tweepy.API(auth) listen = SListener(api, 'mexico') stream = tweepy.Stream(auth, listen) print "Streaming started..." try: stream.filter(locations=[ -99.36,19.11,-98.97,19.57 ]) except: print "error!" stream.disconnect()
def main(): #track = ['#targets', '#iceisis', '#opiceisis'] track = ['Targeted IS accounts'] follow = [ '3012875395', '3012814332', '82415925', '3425725672', '4720033461', '3428485468', '3063852029', '3066135370' ] reload(sys) sys.setdefaultencoding('utf-8') name = datetime.datetime.strftime(datetime.datetime.now(), 'luckytroll%Y.%m.%d.%H.%M.%S') listen = SListener(authKit.api, "reports/" + name) stream = tweepy.Stream(authKit.auth, listen) print "Streaming started..." try: stream.filter(track=track, follow=follow) except: print "error!" stream.disconnect()
def main(): # Handle command line arguments parser = argparse.ArgumentParser( description="Twitter 1.1 Stream Tweet Collector Using Tweepy") parser.add_argument( 'hashtag', help="Specify the keyword or hashtag you wish to return") args = parser.parse_args() hashtag = args.hashtag #Begin script track = [hashtag] listen = SListener(api, hashtag) stream = tweepy.Stream(auth, listen) print "Streaming started ..." try: stream.filter(track=track) except: print "error!" stream.disconnect()
def main(): prefix = 'X1Stream' track = [] """ Obteniendo todas las palabras que se encuentras en el archivo diccionario guardandolas en la variable "track", se omiten lineas en blanco try: print "Tamano Inicial del archivo existente: " + str((os.path.getsize(prefix)/1024/1024)) + " MB" except: print "Creando archivo ..." """ with open("diccionary.txt") as f: for line_terminated in f: line = line_terminated.rstrip('\n') if line != "" and not (line in track): track.append(line) print "Se agragaron " + str(len(track)) + " palabras DESDE el diccionario" while True: # f=open('output.txt', 'w') # f.write("\n".join(track)) #track = ['obama', 'romney'] listen = SListener(api, prefix) stream = tweepy.Stream(auth, listen) print "Streaming started..." try: #stream.filter(languages=['en'],track = track) stream.filter(track=track) # print "{ ok el stream es el del problema}" except: print time.strftime( '%H:%M:%S') + " error! --- Intentado reconectar en 3s "
from keys_secret import access_token, access_token_secret # consumer key authentication auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) # set up the API with the authentication handler api = API(auth) # set up words to hear keywords_to_hear = [ '#climatechange', '#climatestrike', '#globalwarming', 'parisagreement', 'carbonprice', 'savetheplanet' ] # instantiate the SListener object listen = SListener(api) # instantiate the stream object stream = Stream(auth, listen) # create a engine to the database engine = create_engine("sqlite:///tweets.sqlite") # if the database does not exist if not database_exists(engine.url): # create a new database create_database(engine.url) # begin collecting data while True: # maintian connection unless interrupted try:
from slistener import SListener import json import time import tweepy import sys #authObj = json.loads( open('keys.json', 'r').read() ) ## authentication access_token = "FGw5OIcXnaS9w4E1ApbElbxjxkSGNRtD6LENKeMw78" access_token_secret = "xNomP4p90I1oWCLp3cAhH0BwIvPu0l3y2YvxpvthNM2Y4" consumer_key = "jdlBbsGOvrceuji38Yu5MA" consumer_secret = "FGw5OIcXnaS9w4E1ApbElbxjxkSGNRtD6LENKeMw78" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) ## set up words to track track = ['trump', 'clinton'] listen = SListener(api, 'election2016') stream = tweepy.Stream(auth, listen) print("Streaming started...") stream.filter(track=track) ## alternative endpoints for filter include follow and locations ## https://dev.twitter.com/streaming/reference/post/statuses/filter
def main(mode=1): track = ['sochi'] follow = [] listen = SListener(api, 'test')