本文整理汇总了Python中TwitterAPI.TwitterOAuth.read_file方法的典型用法代码示例。如果您正苦于以下问题:Python TwitterOAuth.read_file方法的具体用法?Python TwitterOAuth.read_file怎么用?Python TwitterOAuth.read_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterAPI.TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth.read_file方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_twitter_api
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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
示例2: getAppObject
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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
示例3: init_api
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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
示例4: main
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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)
示例5: MongoClient
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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')
示例6: print
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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:
示例7: TwitterAPI
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
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()})
示例8: TwitterAPI
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
#!/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)
示例9: setUp
# 需要导入模块: from TwitterAPI import TwitterOAuth [as 别名]
# 或者: from TwitterAPI.TwitterOAuth import read_file [as 别名]
def setUp(self):
"""Read credentials from TwitterAPI/credentials.txt. You
must copy your credentials into this text file.
"""
self.oa = TwitterOAuth.read_file()