本文整理汇总了Python中twython.Twython.get_retweets方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.get_retweets方法的具体用法?Python Twython.get_retweets怎么用?Python Twython.get_retweets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.get_retweets方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_retweeters
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
def get_retweeters(tweet_id, index):
if index >= 7:
print "sleepy time"
time.sleep(860)
index = 0
APP_KEY = APP_KEYS[index]
APP_SECRET = APP_SECRETS[index]
OAUTH_TOKEN = OAUTH_TOKENS[index]
OAUTH_TOKEN_SECRET = OAUTH_TOKEN_SECRETS[index]
try:
twitter = Twython (APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
#auth = tweepy.OAuthHandler(APP_KEY,APP_SECRET)
#auth.set_access_token(OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
#twitter = tweepy.API(auth)
result = twitter.get_retweets(id=tweet_id, count = 100, trim_user = 1)
rters= []
for r in result:
rtr = r['user']['id']
date = r['created_at']
tup = (rtr,date)
rters.append(tup)
return (rters, index)
except Exception as e:
if "429 (Too Many Requests)" in str(e):
print "\nchanging apps!\n"
new_index = index + 1
return get_retweeters(tweet_id, new_index)
elif "401 (Unauthorized)" in str(e):
print "401 error"
return ([],index)
elif "404 (Not Found)" in str(e):
print "404 error"
return ([],index)
else:
print e
return ([],index)
示例2: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
class TwythonAPITestCase(unittest.TestCase):
def setUp(self):
self.api = Twython(app_key, app_secret,
oauth_token, oauth_token_secret)
# Timelines
def test_get_mentions_timeline(self):
'''Test returning mentions timeline for authenticated user succeeds'''
self.api.get_mentions_timeline()
def test_get_user_timeline(self):
'''Test returning timeline for authenticated user and random user
succeeds'''
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter') # Random User Timeline
def test_get_protected_user_timeline_following(self):
'''Test returning a protected user timeline who you are following
succeeds'''
self.api.get_user_timeline(screen_name=protected_twitter_1)
def test_get_protected_user_timeline_not_following(self):
'''Test returning a protected user timeline who you are not following
fails and raise a TwythonAuthError'''
self.assertRaises(TwythonAuthError, self.api.get_user_timeline,
screen_name=protected_twitter_2)
def test_get_home_timeline(self):
'''Test returning home timeline for authenticated user succeeds'''
self.api.get_home_timeline()
# Tweets
def test_get_retweets(self):
'''Test getting retweets of a specific tweet succeeds'''
self.api.get_retweets(id=test_tweet_id)
def test_show_status(self):
'''Test returning a single status details succeeds'''
self.api.show_status(id=test_tweet_id)
def test_update_and_destroy_status(self):
'''Test updating and deleting a status succeeds'''
status = self.api.update_status(status='Test post just to get deleted :(')
self.api.destroy_status(id=status['id_str'])
def test_retweet(self):
'''Test retweeting a status succeeds'''
retweet = self.api.retweet(id='99530515043983360')
self.api.destroy_status(id=retweet['id_str'])
def test_retweet_twice(self):
'''Test that trying to retweet a tweet twice raises a TwythonError'''
retweet = self.api.retweet(id='99530515043983360')
self.assertRaises(TwythonError, self.api.retweet,
id='99530515043983360')
# Then clean up
self.api.destroy_status(id=retweet['id_str'])
def test_get_oembed_tweet(self):
'''Test getting info to embed tweet on Third Party site succeeds'''
self.api.get_oembed_tweet(id='99530515043983360')
def test_get_retweeters_ids(self):
'''Test getting ids for people who retweeted a tweet succeeds'''
self.api.get_retweeters_ids(id='99530515043983360')
# Search
def test_search(self):
'''Test searching tweets succeeds'''
self.api.search(q='twitter')
# Direct Messages
def test_get_direct_messages(self):
'''Test getting the authenticated users direct messages succeeds'''
self.api.get_direct_messages()
def test_get_sent_messages(self):
'''Test getting the authenticated users direct messages they've
sent succeeds'''
self.api.get_sent_messages()
def test_send_get_and_destroy_direct_message(self):
'''Test sending, getting, then destory a direct message succeeds'''
message = self.api.send_direct_message(screen_name=protected_twitter_1,
text='Hey d00d!')
self.api.get_direct_message(id=message['id_str'])
self.api.destroy_direct_message(id=message['id_str'])
def test_send_direct_message_to_non_follower(self):
'''Test sending a direct message to someone who doesn't follow you
fails'''
self.assertRaises(TwythonError, self.api.send_direct_message,
screen_name=protected_twitter_2, text='Yo, man!')
# Friends & Followers
def test_get_user_ids_of_blocked_retweets(self):
'''Test that collection of user_ids that the authenticated user does
not want to receive retweets from succeeds'''
#.........这里部分代码省略.........
示例3: max
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
while True:
for orig_tweet_id in tweet_ids:
store = 'db/%s.json' % orig_tweet_id
if os.path.exists(store):
memo = json.loads(open(store).read())
else:
memo = {}
orig_tweet = twitter.show_status(id=orig_tweet_id)
tweet_age = max((datetime.datetime.now() - parse(orig_tweet['created_at']).replace(tzinfo=None)).days, 1)
try:
#get retweets to a specific tweet.
search_results = twitter.get_retweets(id=orig_tweet_id, count=100)
except TwythonError as e:
print e
search_results = []
print len(search_results)
for tweet in search_results:
logging.info("retweeted by @" + str(tweet['user']['screen_name']) + " " + str(tweet[u'user'][u'followers_count']))
age = (datetime.datetime.now() - parse(tweet['user']['created_at']).replace(tzinfo=None)).days
freq = tweet[u'user'][u'statuses_count'] / (age or 1)
if memo.has_key(tweet['user']['screen_name']):
logging.info('already rewarded.')
continue
else:
reward = min(max(int(tweet[u'user'][u'followers_count'] * 0.25), 20), 9 * int(sqrt(tweet[u'user'][u'followers_count'])))
示例4: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
#.........这里部分代码省略.........
# Timelines
def test_get_mentions_timeline(self):
"""Test returning mentions timeline for authenticated user succeeds"""
self.api.get_mentions_timeline()
def test_get_user_timeline(self):
"""Test returning timeline for authenticated user and random user
succeeds"""
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter') # Random User Timeline
def test_get_protected_user_timeline_following(self):
"""Test returning a protected user timeline who you are following
succeeds"""
self.api.get_user_timeline(screen_name=protected_twitter_1)
def test_get_protected_user_timeline_not_following(self):
"""Test returning a protected user timeline who you are not following
fails and raise a TwythonAuthError"""
self.assertRaises(TwythonAuthError, self.api.get_user_timeline,
screen_name=protected_twitter_2)
def test_retweeted_of_me(self):
"""Test that getting recent tweets by authenticated user that have
been retweeted by others succeeds"""
self.api.retweeted_of_me()
def test_get_home_timeline(self):
"""Test returning home timeline for authenticated user succeeds"""
self.api.get_home_timeline()
# Tweets
def test_get_retweets(self):
"""Test getting retweets of a specific tweet succeeds"""
self.api.get_retweets(id=test_tweet_id)
def test_show_status(self):
"""Test returning a single status details succeeds"""
self.api.show_status(id=test_tweet_id)
def test_update_and_destroy_status(self):
"""Test updating and deleting a status succeeds"""
status = self.api.update_status(status='Test post just to get deleted :(')
self.api.destroy_status(id=status['id_str'])
def test_get_oembed_tweet(self):
"""Test getting info to embed tweet on Third Party site succeeds"""
self.api.get_oembed_tweet(id='99530515043983360')
def test_get_retweeters_ids(self):
"""Test getting ids for people who retweeted a tweet succeeds"""
self.api.get_retweeters_ids(id='99530515043983360')
# Search
def test_search(self):
"""Test searching tweets succeeds"""
self.api.search(q='twitter')
# Direct Messages
def test_get_direct_messages(self):
"""Test getting the authenticated users direct messages succeeds"""
self.api.get_direct_messages()
def test_get_sent_messages(self):
"""Test getting the authenticated users direct messages they've
示例5: TwythonEndpointsTestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
class TwythonEndpointsTestCase(unittest.TestCase):
def setUp(self):
client_args = {
'headers': {
'User-Agent': '__twython__ Test'
},
'allow_redirects': False
}
# This is so we can hit coverage that Twython sets
# User-Agent for us if none is supplied
oauth2_client_args = {
'headers': {}
}
self.api = Twython(app_key, app_secret,
oauth_token, oauth_token_secret,
client_args=client_args)
self.oauth2_api = Twython(app_key, access_token=access_token,
client_args=oauth2_client_args)
# Timelines
@unittest.skip('skipping non-updated test')
def test_get_mentions_timeline(self):
"""Test returning mentions timeline for authenticated user succeeds"""
self.api.get_mentions_timeline()
@unittest.skip('skipping non-updated test')
def test_get_user_timeline(self):
"""Test returning timeline for authenticated user and random user
succeeds"""
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter')
# Random User Timeline
@unittest.skip('skipping non-updated test')
def test_get_protected_user_timeline_following(self):
"""Test returning a protected user timeline who you are following
succeeds"""
self.api.get_user_timeline(screen_name=protected_twitter_1)
@unittest.skip('skipping non-updated test')
def test_get_protected_user_timeline_not_following(self):
"""Test returning a protected user timeline who you are not following
fails and raise a TwythonAuthError"""
self.assertRaises(TwythonAuthError, self.api.get_user_timeline,
screen_name=protected_twitter_2)
@unittest.skip('skipping non-updated test')
def test_retweeted_of_me(self):
"""Test that getting recent tweets by authenticated user that have
been retweeted by others succeeds"""
self.api.retweeted_of_me()
@unittest.skip('skipping non-updated test')
def test_get_home_timeline(self):
"""Test returning home timeline for authenticated user succeeds"""
self.api.get_home_timeline()
# Tweets
@unittest.skip('skipping non-updated test')
def test_get_retweets(self):
"""Test getting retweets of a specific tweet succeeds"""
self.api.get_retweets(id=test_tweet_id)
@unittest.skip('skipping non-updated test')
def test_show_status(self):
"""Test returning a single status details succeeds"""
self.api.show_status(id=test_tweet_id)
@unittest.skip('skipping non-updated test')
def test_update_and_destroy_status(self):
"""Test updating and deleting a status succeeds"""
status = self.api.update_status(status='Test post just to get \
deleted :( %s' % int(time.time()))
self.api.destroy_status(id=status['id_str'])
@unittest.skip('skipping non-updated test')
def test_get_oembed_tweet(self):
"""Test getting info to embed tweet on Third Party site succeeds"""
self.api.get_oembed_tweet(id='99530515043983360')
@unittest.skip('skipping non-updated test')
def test_get_retweeters_ids(self):
"""Test getting ids for people who retweeted a tweet succeeds"""
self.api.get_retweeters_ids(id='99530515043983360')
# Search
@unittest.skip('skipping non-updated test')
def test_search(self):
"""Test searching tweets succeeds"""
self.api.search(q='twitter')
# Direct Messages
@unittest.skip('skipping non-updated test')
def test_get_direct_messages(self):
"""Test getting the authenticated users direct messages succeeds"""
self.api.get_direct_messages()
#.........这里部分代码省略.........
示例6: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
OAUTH_TOKEN_SECRET = config.get('Tweet', 'access_secret')
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
orig_tweet_id = 483383384660385792 # sys.argv[1]
store = 'db/%s.json' % orig_tweet_id
if os.path.exists(store):
memo = json.loads(open(store).read())
else:
memo = {}
while True:
try:
#get retweets to a specific tweet.
search_results = twitter.get_retweets(id=orig_tweet_id)
except TwythonError as e:
print e
for tweet in search_results:
logging.info("retweeted by @" + str(tweet['user']['screen_name']))
if memo.has_key(tweet['user']['screen_name']):
logging.info('already rewarded.')
continue
else:
tweet_text= "@tipdoge tip @" + tweet[u'user'][u"screen_name"] + " 100 - Just testing the twitter API. Keep the Doge!"
logging.info(tweet_text)
twitter.update_status(status=tweet_text.encode('UTF-8'))
memo[tweet['user']['screen_name']] = 1
示例7: int
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
try:
# Fix this....
# why aien;t it returning tweets that our ed's have had retweeted?
tweeties = tweets.find(None, sort=[('retweet_count',-1)])
for tweet in tweeties:
if tweet['retweeted_status']['id'] is None:
print tweet['id']
print tweet['retweet_count']
print ""
# tweetid = 605455779580289026
# tweetid = "595218763743666177"
# tweetid = 595178774209101824
params = {'id':tweet['id'], 'count':100}
results = timeline_twitter.get_retweets(**params)
for result in results:
print result['id']
print "end of results"
except TwythonRateLimitError, e:
print "Rate-limit exception encountered. Sleeping for ~ 15 min before retrying"
reset = int(timeline_twitter.get_lastfunction_header('x-rate-limit-reset'))
wait = max(reset - time.time(), 0) + 10 # addding 10 second pad
time.sleep(wait)
except Exception, e:
print e
print "Non rate-limit exception encountered. Sleeping for 15 min before retrying"
time.sleep(60*15)
示例8: window
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_retweets [as 别名]
response = timeline_twitter.get_retweeters_ids(**params)
#response['previous_cursor']
#response['previous_cursor_str']
print response['next_cursor']
#response['next_cursor_str']
for retweeter_id in response['ids']:
print retweeter_id
"""
Returns a collection of the 100 most
recent retweets of the tweet specified by the id parameter.
Requests / 15-min window (user auth) 15
Requests / 15-min window (app auth) 60
you CANNOT cursor this...
"""
params = {'count':100, 'id':orig_tweet_id}
response= timeline_twitter.get_retweets(**params)
# print response
for item in response:
print item['user']['screen_name']