Exemplo n.º 1
0
def reconnect(wait):
	for i in range(wait, 0, -1):
		print "Reconnecting in %d seconds..." % (i,)
		time.sleep(1)
		blank_current_readline()

	print 'Reconnecting...'

	auth = tweepy.OAuthHandler(settings.cKey, settings.cSecret)
	auth.set_access_token(settings.aToken, settings.aSecret)

	api = tweepy.API(auth)
	listener = TweetListener()

	debug_print('\nStarting stream for #%s...' % (settings.hashtag1,))

	stream = Stream(auth, listener)
	print 'Now scanning for #%s...\n\n\n\n' % (settings.hashtag)

	stream.filter(track=['#' + settings.hashtag1])
import json
import tweepy
from tweepy import OAuthHandler
from collections import Counter
from prettytable import PrettyTable
from operator import itemgetter
import auth

CONSUMER_KEY = auth.CONSUMER_KEY
CONSUMER_SECRET = auth.CONSUMER_SECRET
OAUTH_TOKEN = auth.OAUTH_TOKEN
OAUTH_TOKEN_SECERT = auth.OAUTH_TOKEN_SECERT

auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECERT)
api = tweepy.API(auth)

count = 100

query = 'brazil'

#get all tweets for the search query
results = [status for status in tweepy.Cursor(api.search, q=query).items(count)]

min_retweets = 10 # the min amount of times a status is retweeted to gain entry to our list.
                  # reset this value to suit your own tests

pop_tweets = [ status for status in results if status._json['retweet_count'] > min_retweets ]

# create a dictionary of tweet text and aassociated retweets
tweets_tup = tuple([(tweet._json['text'].encode('utf-8'),tweet._json['retweet_count']) for tweet in pop_tweets])
Exemplo n.º 3
0
        #print status.text
        self.total += 1
        if status.coordinates is not None:
            self.tagged += 1
            self.data[status.id] = status
        #if self.total % 10 == 0:
           # print (self.tagged * 1.0 / self.total * 100.0)
        if time.time() - self.t > self.runtime:
            print self.total, self.tagged, self.tagged * 1.0 / self.total * 100.0
            pickle.dump(self.data, open('statuses.p', 'wb'))
            return False

if __name__ == '__main__':
    #first, authorize with tweepy
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)
    
    ml = generic_listener()
    stream = tweepy.Stream(auth = api.auth, listener=ml)

    # using this as a hack to get global tweets in english
    #stream.filter(languages=["en"], locations=[-180,-90,180,90])
    
    # use this to track oklahoma tweets
    stream.filter(locations=[-99.98,33.56,-94.43,37.01] )
    # when run at 7:15 am on Feb11,2016, this yielded:
    # 2212 tweets, 302 tagged, 13.6528028933%
    
    # use this to track health keywords
    #stream.filter(track=['diabetes'])
Exemplo n.º 4
0
#!/usr/bin/env python
# Get the statuses from the members of the List
# Ravs, FALL 2013

import api
from error import TweepError
import RavsKeys
import time
import auth
import cursor

#Twitter API global instance after getting OAuth'd
auth = auth.OAuthHandler(RavsKeys.consumer_key, RavsKeys.consumer_secret)
auth.set_access_token(RavsKeys.access_token, RavsKeys.access_token_secret)
api = api.API(auth)

# Write tweets in file
conf_training_set = open("conf_training_set.txt", "w")
list_member = open("list_member.txt","w")

# Method to stop execution and enter in sleep mode for 15Min span
def standby():
	print "Doh!! Rate limit exceeded, taking a nap now!!"
	time.sleep(910)
	print "Sleeping is just waste of time, resume execution"

# Method to return remaining api calls
def remaining_rate_limit():
	try:
		return api.rate_limit_status()['resources']['lists']['/lists/statuses']['remaining']
	except:
Exemplo n.º 5
0
c_key = auth.MyAuth.c_key
c_secret = auth.MyAuth.c_secret
a_token = auth.MyAuth.a_token
a_secret = auth.MyAuth.a_secret

class Listener(StreamListener):

    def on_data(self, data):
        print data

    def on_error(self, status):
        print status


auth = tweepy.OAuthHandler(c_key, c_secret)
auth.set_access_token(a_token, a_secret)

api = tweepy.API(auth)

i = 0

for status in tweepy.Cursor(api.user_timeline, screen_name = 'tagesschau').items():
    # process status here
    i += 1
    if i > 800:
        break

print 'Received ' + str(i) + 'items'


Exemplo n.º 6
0

def print_msgs_info(tw_api):
    msgs = get_messages(tw_api)
    for msg in msgs:
        print("ID:", msg[0], "\nText:", msg[1], "\nSender ID:", msg[-1], "\n-------------------------------------------")


def main(tw_api):
    while True:
        print("Creating 'functionality_cycle'...")
        functionality_cycle = threading.Thread(target=manage_messages, args=(tw_api, "last_id.txt"))
        print("Starting 'functionality_cycle'...")
        functionality_cycle.start()
        print("Waiting for 'functionality_cycle' to finish...")
        functionality_cycle.join()
        print("'functionality_cycle' finished")
        sleep(120)


if __name__ == "__main__":
    consumer_key = auth.api_key
    consumer_secret_key = auth.api_secret_key
    access_key = auth.access_token
    access_secret_key = auth.access_token_secret

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret_key)
    auth.set_access_token(access_key, access_secret_key)
    api = tweepy.API(auth)
    main(api)
Exemplo n.º 7
0
#!/usr/bin/env python
# Get the statuses from the members of the List
# Ravs, FALL 2013

import api
from error import TweepError
import RavsKeys
import time
import auth
import cursor

#Twitter API global instance after getting OAuth'd
auth = auth.OAuthHandler(RavsKeys.consumer_key, RavsKeys.consumer_secret)
auth.set_access_token(RavsKeys.access_token, RavsKeys.access_token_secret)
api = api.API(auth)

# Write tweets in file
conf_training_set = open("conf_training_set.txt", "w")
list_member = open("list_member.txt", "w")


# Method to stop execution and enter in sleep mode for 15Min span
def standby():
    print "Doh!! Rate limit exceeded, taking a nap now!!"
    time.sleep(910)
    print "Sleeping is just waste of time, resume execution"


# Method to return remaining api calls
def remaining_rate_limit():
    try:
Exemplo n.º 8
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import tweepy
import time, sys, random
import auth
print "OK GOOD START TEAM!"

argfile = str(sys.argv[1])

CONSUMER_KEY = 'Mg2JY9DS9qSQcEjAIBrR97gFh' 
CONSUMER_SECRET = auth.CONSUMER_SECRET
ACCESS_TOKEN = '752964356187357184-WrLmQXh7Vy2ucUNXmH7sZwatOvLhRGa'
ACCESS_SECRET =  auth.ACCESS_SECRET
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)

filename = open(argfile, 'r')
f = filename.readlines()
filename.close()
random.shuffle(f)

for line in f:
    api.update_status(line)
    print line
    time.sleep(900)
Exemplo n.º 9
0
#importing libraries
import tweepy
import auth

#creating Oauth authentication
auth = tweepy.OAuthHandler(auth.consumer_key, auth.consumer_secret)
auth.set_access_token(auth.access_token, auth.access_token_secret)

#object for API class in tweepy
api = tweepy.API(auth)

#input the person username
print('Enter the username')
screen_name = input()

#initializing lists and variables
info = api.get_user(screen_name)


#Function definitions
#Function to print timeline of user
def user_tweets(screen_name):
    tweet_txt = []
    public_tweets = api.user_timeline(
        screen_name)  #count parameter can also be passed as user_time method
    for tweet in public_tweets:
        tweet_txt.append(tweet.text.encode('UTF-8').decode('UTF-8'))
    for i in tweet_txt:
        try:
            print(i)
        except UnicodeEncodeError:
Exemplo n.º 10
0
    ## Setting IRC cli.
    ## logging.basicConfig(level=logging.DEBUG)
    cli = IRCClient(MyHandler, host=HOST, port=PORT, nick=NICK)  # ,connect_cb=connect_cb)
    conn = cli.connect()


if __name__ == "__main__":
    status_queue = Queue.Queue()

    consumer_key = auth.consumer_key
    consumer_secret = auth.consumer_secret
    key = auth.key
    secret = auth.secret

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(key, secret)
    api = tweepy.API(auth)
    stream = tweepy.Stream(auth=auth, listener=StreamWatcherListener(status_queue))

    ## Setting IRC cli.
    ircinit()

    track_list = []
    follow_list = []
    stream.filter(follow_list, track_list, True)
    try:
        main()
    except KeyboardInterrupt:
        print "Interrupted"
        exit()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  1 12:45:09 2018

@author: aayushsharma
"""
import auth
import tweepy
from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
import matplotlib.pyplot as plt
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

#user = api.get_user('twitter')
#print(user.screen_name)
#print(user.followers_count)

query = input("Enter your query: ")
#Get tweets using tweepy
max_tweets = 10
tweets = [
    status for status in tweepy.Cursor(
        api.search,
        q=query,
        result_type="recent",
        tweet_mode="extended",
        lang="en",
    ).items(max_tweets)
]
def authentication():
    import auth
    auth = tweepy.OAuthHandler(auth.consumer_key, auth.consumer_secret)
    auth.set_access_token(auth.access_token, auth.access_token_secret)
    api = tweepy.API(auth)
    return api