当前位置: 首页>>代码示例>>Python>>正文


Python TwitterAPI.TwitterOAuth类代码示例

本文整理汇总了Python中TwitterAPI.TwitterOAuth的典型用法代码示例。如果您正苦于以下问题:Python TwitterOAuth类的具体用法?Python TwitterOAuth怎么用?Python TwitterOAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TwitterOAuth类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_async

    def run_async(self):
        auth = TwitterOAuth.read_file_object(self.wrapper.getFileObject(__file__, "TwitterAPI/credentials.txt"))
        api = TwitterAPI(auth.consumer_key, auth.consumer_secret, auth.access_token_key, auth.access_token_secret)

        # list of user id to follow (by Nazli)
        """ '@StiftenAGF','@jpaarhus','#Aarhus','@AarhusKultur','@smagaarhus','@AarhusNyheder','@AarhusPortaldk',
        '@Aarhus2017','@OpenDataAarhus', '@aarhusupdate','@AskVest','@SundhedOgOmsorg','@ArhusVejr','@aarhus_ints',
        '@AGFFANdk','@AarhusCykelby','@VisitAarhus','@larshaahr' """

        users = ['3601200017', '3370065087', '3330970365', '2911388001', '2706568231',
			'2647614595', '2201213730', '1324132976', '1065597596', '816850003', '763614246',
			'210987829', '159110346', '112585923', '77749562', '38227253', '36040150']

        # list of terms to track
        tracks = ['#Aarhus']
        print "TAA ready."
        try:
            r = api.request('statuses/filter', {'locations': self.location, 'follow': ','.join(users), 'track': ','.join(tracks)})
        except:
            print r.text

        for item in r:
            self.tweet = item
            # print item
            self.wrapper.update()
            if self.abort.is_set():
                break
开发者ID:CityPulse,项目名称:CP_Resourcemanagement,代码行数:27,代码来源:twitter.py

示例2: init_twitter_api

 def init_twitter_api(self):
   o = TwitterOAuth.read_file("credentials.txt")
   api = TwitterAPI(o.consumer_key,
                  o.consumer_secret,
                  o.access_token_key,
                  o.access_token_secret)
   return api
开发者ID:fdrozdowski,项目名称:PlatypusPi,代码行数:7,代码来源:platypus.py

示例3: getAppObject

    def getAppObject(self):
        if self.globalAppObj is None:
            # Using OAuth1...
            o = TwitterOAuth.read_file()
            self.globalAppObj = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)

        return self.globalAppObj
开发者ID:mjaglan,项目名称:TextSentiment.V1.a.public,代码行数:7,代码来源:TwitterStream.py

示例4: init_api

def init_api(credentials_file):
	"""Initialize a connection to Twitter.
	
	Arguments:
	credentials_file -- A file with Twitter developer credentials.
	
	Return an authenticated instance of TwitterAPI.
	"""
	auth = TwitterOAuth.read_file(credentials_file)
	api = TwitterAPI(auth.consumer_key, auth.consumer_secret, auth.access_token_key, auth.access_token_secret)
	return api
开发者ID:supersam654,项目名称:Tweetalyzer,代码行数:11,代码来源:backend.py

示例5: main

def main():

#Specify time to run script
        EndDate='2013-11-30'

#loop to change filenames after day change
        while str(date.today())!=EndDate:
                dte=str(date.today())

# SAVE YOUR APPLICATION CREDENTIALS IN credentials.txt.
                o = TwitterOAuth.read_file('credentials.txt')
                api = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)

#see if authentications was successful
                r = api.request('account/verify_credentials')
                print(r.text)

#open timestamped file to store JSON tweets in: 
                d=date.today()
                d=str(d)
                filename=d+"_tweets_thanksgiving_blackfriday"
                file_twts= codecs.open(filename,"ab",encoding="utf-8")

#stream tweets with a given keyword and store it in a file
#given using statuses/filter and using track : text terms seperated with , are regarded as or and those seperated by whtespace are regarded as and
                try :   

                        for item in api.request('statuses/filter', {'track':'thanksgiving, black friday, christmas, new year'}):
                                #print(item)
                                #indent to put on new lne indent=2
                                item=convert_reduced_json(item)
                                json.dump(item,file_twts)
                                file_twts.write('\n')
                                if str(date.today())!=dte:
                                        break
                        file_twts.close()
                except Exception as e:
                                print(e)
开发者ID:sbondada,项目名称:electalytics,代码行数:38,代码来源:Selective_fields_Festival_tweets.py

示例6: MongoClient

        parser.add_argument('-endpoint', metavar='ENDPOINT', type=str, help='Twitter endpoint')
        parser.add_argument('-parameters', metavar='NAME_VALUE', type=str, help='parameter NAME=VALUE', nargs='+')
        parser.add_argument('-fields', metavar='FIELD', type=str, help='print a top-level field in the json response', nargs='+')
        args = parser.parse_args()        

        try:
            client = MongoClient('localhost', 27017)
            db = client['devtweets']
            tweets = db.tweets
        except Exception as e:
                print('*** STOPPED %s' % str(e))
            

        try:
                params = to_dict(args.parameters)
                oauth = TwitterOAuth.read_file('./credentials.txt')
                api = TwitterAPI(oauth.consumer_key, oauth.consumer_secret, oauth.access_token_key, oauth.access_token_secret)
                """response = api.request('statuses/filter', {'locations':'-102.878723,21.659981,-101.997757,22.473779'})"""
                #response = api.request('search/tweets', {'q':'Aguascalientes 4sq com, ags 4sq com', 'count': 450})
                lastTweet = tweets.find({}).sort('id', -1).limit(1)
                str_lastTweetId = str(lastTweet[0]["id"])
                pager = TwitterRestPager(api, 'search/tweets', {'q':'Aguascalientes 4sq com, ags 4sq com', 'count':100, 'since_id': str_lastTweetId})

                #for item in response.get_iterator():
                for item in pager.get_iterator(10):
                    print item
                    tweets.insert(item)
                    #print ('\n' % pager.get_rest_quota())
				
        except KeyboardInterrupt:
                print('\nTerminated by user')
开发者ID:agencia,项目名称:tweetmines,代码行数:31,代码来源:agent.py

示例7: print

				if item['code'] == 131:
					continue # ignore internal server error
				elif item['code'] == 88:
					print('Suspend search until %s' % search.get_quota()['reset'])
				raise Exception('Message from twiter: %s' % item['message'])
				
				
if __name__ == '__main__':
	parser = argparse.ArgumentParser(description='Search tweet history.')
	parser.add_argument('-location', type=str, help='limit tweets to a place')
	parser.add_argument('-oauth', metavar='FILENAME', type=str, help='read OAuth credentials from file')
	parser.add_argument('-radius', type=float, help='distance from "location" in km')
	parser.add_argument('words', metavar='W', type=str, nargs='+', help='word(s) to search')
	args = parser.parse_args()	

	oauth = TwitterOAuth.read_file(args.oauth)
	api = TwitterAPI(oauth.consumer_key, oauth.consumer_secret, oauth.access_token_key, oauth.access_token_secret)
	
	try:
		if args.location:
			lat, lng, radius = GEO.get_region_circle(args.location)
			print('Google found region at %f,%f with a radius of %s km' % (lat, lng, radius))
			if args.radius:
				radius = args.radius
			region = (lat, lng, radius)
		else:
			region = None
		search_tweets(api, args.words, region)
	except KeyboardInterrupt:
		print('\nTerminated by user\n')
	except Exception as e:
开发者ID:Web5design,项目名称:TwitterGeoPics,代码行数:31,代码来源:GetOldGeo.py

示例8: TwitterAPI

		target_csv.writeheader()
	target_csv.writerows(data_lst)
	target.close()
	
	#fieldnames = ['tweet_date', 'tweet_id', 'tweet_date', 
	#		dict_temp['tweet_id'] = item['id_str']
	#		dict_temp['tweet_date'] = item['created_at']
	#		dict_temp['user_name'] = item['user']['name']
	#		dict_temp['user_screen_name'] = item['user']['screen_name']
	#		dict_temp['tweet_text'] = item['text']
	return
	
#############################################################################################################################################################
#############################################################################################################################################################
# SAVE YOUR APPLICATION CREDENTIALS IN TwitterAPI/credentials.txt.
o = TwitterOAuth.read_file()
api = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)



try:
	if TEST_NUMBER == 0:

		# VERIFY YOUR CREDS
		r = api.request('account/verify_credentials')
		print(r.text)

	if TEST_NUMBER == 1:

		# POST A TWEET 
		r = api.request('statuses/update', {'status':'the time is now %s' % datetime.now()})
开发者ID:williampbarr,项目名称:Big_Data-Python_Twitter,代码行数:31,代码来源:StreamingTwitter+-+v03_06.py

示例9: TwitterAPI

#!/usr/bin/python3
# -*- encoding: utf-8 -*-
from TwitterAPI import TwitterAPI, TwitterOAuth, TwitterRestPager
import html, sys

o = TwitterOAuth.read_file('credentials.txt')
api = TwitterAPI(
	o.consumer_key,
	o.consumer_secret,
	o.access_token_key,
	o.access_token_secret)
开发者ID:lanodan,项目名称:scripts,代码行数:11,代码来源:replies.py

示例10: setUp

	def setUp(self):
		"""Read credentials from TwitterAPI/credentials.txt. You
		must copy your credentials into this text file.
		"""
		self.oa = TwitterOAuth.read_file()
开发者ID:helshowk,项目名称:TwitterAPI,代码行数:5,代码来源:test_oauth.py


注:本文中的TwitterAPI.TwitterOAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。