def __init__(self, twitter_auth_params): ''' Constructor ''' auth = OAuthHandler(twitter_auth_params.getConsumerKey(), twitter_auth_params.getConsumerSecret()) auth.secure = True auth.set_access_token(twitter_auth_params.getAccessTokenKey(), twitter_auth_params.getAccessTokenSecret()) self.__twitterApi = API(auth)
def start_twitter(): global api global auth auth = OAuthHandler(config['CONSUMER_TOKEN'], config['CONSUMER_SECRET']) auth.secure = True auth.set_access_token(config['ACCESS_TOKEN'], config['ACCESS_TOKEN_SECRET']) api = API(auth)
def start_twitter(): global api global auth auth = OAuthHandler(config['CONSUMER_TOKEN'], config['CONSUMER_SECRET']) auth.secure = True auth.set_access_token(config['ACCESS_TOKEN'], config['ACCESS_TOKEN_SECRET']) api = API(auth)
def main(): print('Welcome to Snap \'N\' Go!') auth = OAuthHandler(consumer_key, consumer_key_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) dmlistener = Stream(auth, DMListener()) dmlistener.userstream()
def main(): SnapNGo.readFile("Sci_Center_Map.txt") print('Welcome to Snap \'N\' Go!') auth = OAuthHandler(consumer_key, consumer_key_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) snap = SnapNGo() snap.selectAction()
def authenticate_twitter_api(): auth = OAuthHandler(twitter_credentials.CONSUMER_KEY, twitter_credentials.CONSUMER_SECRET) auth.secure = True auth.set_access_token(twitter_credentials.ACCESS_TOKEN, twitter_credentials.ACCESS_TOKEN_SECRET) tweepyApi = tweepy.API(auth, parser=tweepy.parsers.JSONParser() \ , wait_on_rate_limit=True, wait_on_rate_limit_notify=True) return tweepyApi
def init_api(self): oauth_handler = TweepyOAuthHandler(self._consumer_key, self._consumer_secret) oauth_handler.secure = configuration.twitter['use_https'] oauth_handler.set_access_token(self._access_token_key, self._access_token_secret) self._api = BaseTweepyApi(oauth_handler)
def twitter_auth(self, next_page: str = "/") -> OAuthHandler: """ :param next_page: the page to redirect to after the auth flow :return: the twitter oauth handler """ auth = OAuthHandler(self.credentials.consumer_key, self.credentials.consumer_secret, callback=self.callback(next_page)) auth.secure = True return auth
def init_api(self): oauth_handler = TweepyOAuthHandler( self._consumer_key, self._consumer_secret) oauth_handler.secure = configuration.twitter['use_https'] oauth_handler.set_access_token(self._access_token_key, self._access_token_secret) self._api = BaseTweepyApi(oauth_handler)
def main(): try: auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) api = API(auth) print(api.me().name) stream = Stream(auth, StdOutListener()) stream.userstream() except BaseException as e: print("Error in main()", e)
def main(): try: auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) api = API(auth) print(api.me().name) stream = Stream(auth, StdOutListener()) stream.userstream() except BaseException as e: print("Error in main()", e)
def main(): global api try: auth = OAuthHandler(CONSUMER_TOKEN, CONSUMER_SECRET) auth.secure = True auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = API(auth) stream = Stream(auth, StdOutListener()) stream.userstream() except BaseException as e: print("Error in main()", e)
def main(): global api try: auth = OAuthHandler(CONSUMER_TOKEN, CONSUMER_SECRET) auth.secure = True auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = API(auth) stream = Stream(auth, StdOutListener()) stream.userstream() except BaseException as e: print("Error en main()", e)
def main(): SnapNGo.readFile("Sci_Center_Map.txt") print('Welcome to Snap \'N\' Go!') auth = OAuthHandler(consumer_key, consumer_key_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) conn = pymysql.connect(host=host, user=user, password=password, db=db) curs = conn.cursor() curs.execute('select * from users') results = curs.fetchall() print results snap = SnapNGo() snap.selectAction()
def get_auth_link_and_show_token(): auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.secure = True auth_url = auth.get_authorization_url() input( "Log in to https://twitter.com as the user you want to tweet as and hit enter." ) input("Visit %s in your browser and hit enter." % auth_url) pin = input("What is your PIN: ") token = auth.get_access_token(verifier=pin) print( "\nThese are your access token and secret.\nDO NOT SHARE THEM WITH ANYONE!\n" ) print("ACCESS_TOKEN\n%s\n" % token[0]) print("ACCESS_TOKEN_SECRET\n%s\n" % token[1])
def main(): try: auth = OAuthHandler(keys.consumer_key, keys.consumer_secret) auth.secure = True auth.set_access_token(keys.access_token, keys.access_token_secret) api = API(auth) # If the authentication was successful, you should # see the name of the account print out print(api.me().name) stream = Stream(auth, StdOutListener()) stream.userstream() except BaseException as e: print("Error in main()", e)
def main(): try: auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token_key, access_token_secret) api = API(auth) # If the authentication was successful, you should # see the name of the account print out print(api.me().name) stream = Stream(auth, Listener()) stream.userstream() except BaseException as e: print("Error in main()", e)
def main(): #This handles Twitter authetification and the connection to Twitter Streaming API l = TwitterListener() auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) stream = Stream(auth=auth, listener=l, filter_level='medium', timeout=3000) while True: try: #This line filter Twitter Streams to capture data by the keywords #stream.filter(track=terms,languages=["en"])## This will feed the stream all mentions of 'keyword' #stream.sample()##This will feed the stream without keywords or filter #setting location to world wide stream.filter(locations=[-180, -90, 180, 90]) break except Exception, e: # Abnormal exit: Reconnect print "Now sleep...Exception:", e nsecs = random.randint(10, 20) time.sleep(nsecs)
def main(): logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # create a file handler handler = logging.FileHandler('goddit.log') handler.setLevel(logging.INFO) # create a logging format formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # add the handlers to the logger logger.addHandler(handler) try: auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) api = API(auth) # If the authentication was successful, you should # see the name of the account print out #print(api.me().name) stream = Stream(auth, tweetchazzer(api=api, logger=logger)) s = stream.userstream() #while True: # s = stream.filter(track=['tweetchazzer']) #print(str(s)) except BaseException as e: print("Error in main()" +str(e))
def __init__(self, consumer_key, consumer_secret, access_token, access_token_secret, botometer_key): # Init the keys and secrets self._consumer_key = consumer_key self._consumer_secret = consumer_secret self._access_token = access_token self._access_token_secret = access_token_secret self._botometer_key = botometer_key # Set up OAuth API; slow but must be used for almost all kinds of # requests auth = OAuthHandler(self._consumer_key, self._consumer_secret) auth.set_access_token(self._access_token, self._access_token_secret) self._oauth_api = API(auth) # Set up AppAuth API; faster and also allows for more requests, can # only be used for certain stuff auth = AppAuthHandler(self._consumer_key, self._consumer_secret) auth.secure = True self._appauth_api = API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) # Botometer object self._botometer = botometer.Botometer( wait_on_ratelimit=True, mashape_key=self._botometer_key, consumer_key=self._consumer_key, consumer_secret=self._consumer_secret, access_token=self._access_token, access_token_secret=self._access_token_secret) # Constants and filters self._mentions_threshold = 100 self._bot_threshold = 0.6 # Establish connection to db self.connection = psycopg2.connect(**consts.db_creds) self.cursor = self.connection.cursor()
def get_token(): # Get authorization information from secure file with open("etc/auth/auth.txt", "r") as authFile: consumerKey = authFile.readline().strip() consumerSecret = authFile.readline().strip() # Authenticate the twitter consumer key twitter_auth = OAuthHandler(consumerKey, consumerSecret) twitter_auth.secure = True authUrl = twitter_auth.get_authorization_url() # go to this URL to authorize print("PLase visit this link and authorize the app ==> " + authUrl) print ("Enter the Authorization PIN") # Write the access tokens to file pin = input().strip() # strip the new line character from pressing 'enter' token = twitter_auth.get_access_token(verifier=pin) with open("etc/auth/tokens.txt", "w") as accessTokenFile: accessTokenFile.write(token[0]+'\n') # '\n' indicates a newline char accessTokenFile.write(token[1]+'\n') return
from tweepy import Stream from py2neo import Graph from neo4j import tweet_to_neo4j #implement config parser to avoid showing secrets on github config = ConfigParser() config.read('config.ini') consumer_key = config.get("twitter", "consumer_key") consumer_secret = config.get("twitter", "consumer_secret") access_token_key = config.get("twitter", "access_token_key") access_token_secret = config.get("twitter", "access_token_secret") #authoize th twitter stream auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token_key, access_token_secret) #neo4j graph graph = Graph("http://*****:*****@127.0.0.1:7474/db/data/") class TwitterListener(StreamListener): """ A Handlers which sends tweets received by the string to the current RDD """ def __init__(self): self.hashtag_bucket = [] # def on_connect(self): # self.start_time = time.time() # time.sleep(1)
from py2neo import Graph from neo4j import tweet_to_neo4j #implement config parser to avoid showing secrets on github config = ConfigParser() config.read('config.ini') consumer_key = config.get("twitter", "consumer_key") consumer_secret = config.get("twitter", "consumer_secret") access_token_key = config.get("twitter", "access_token_key") access_token_secret = config.get("twitter", "access_token_secret") #authoize th twitter stream auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token_key, access_token_secret) #neo4j graph graph = Graph("http://*****:*****@127.0.0.1:7474/db/data/") class TwitterListener(StreamListener): """ A Handlers which sends tweets received by the string to the current RDD """ def __init__(self): self.hashtag_bucket = [] # def on_connect(self): # self.start_time = time.time() # time.sleep(1)
def on_error(self, status): print status return True # Don't kill the stream # new code def on_timeout(self): # new code return True # Don't kill the stream # new code def streamingTwitter(): try: #This line filter Twitter Streams #SW corner first, East/West point first (longitude) #US stream.filter(locations = [-125.011, 24.047, -67.3, 49.458]) stream.filter(locations=[-125.011, 24.047, -67.3, 49.458]) except UnicodeDecodeError: #Skip tweets with UnicodeDecodeError and recall streamingTwitter streamingTwitter() if __name__ == '__main__': #This handles Twitter authentication and the connection to Twitter Streaming API l = StdOutListener() auth = OAuthHandler(consumer_key, consumer_secret) auth.secure = True # new code auth.set_access_token(access_token, access_token_secret) stream = Stream(auth, l) streamingTwitter()