本文整理汇总了Python中tweepy.API.update_status方法的典型用法代码示例。如果您正苦于以下问题:Python API.update_status方法的具体用法?Python API.update_status怎么用?Python API.update_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tweepy.API
的用法示例。
在下文中一共展示了API.update_status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TwitterBackend
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class TwitterBackend(ShareBackend):
"""Implements Tweepy API
Backends Settings:
api_token -- a valid oauth api token. This is your app's token.
api_secret -- a valid oauth api secret. This is your app's secret.
consumer_token -- optional consumer token.
consumer_secret -- optional consumer secret.
Twitter Specific Settings:
use_tco -- True or False, use Twitter's t.co shortner.
"""
def __init__(self, *args, **kwargs):
super(TwitterBackend, self).__init__(*args, **kwargs)
# handle twitter custom parameters
self.use_tco= kwargs.get('use_tco') or True
# create a tweepy API
from tweepy import API, OAuthHandler
auth = OAuthHandler(self.consumer_token, self.consumer_secret)
auth.set_access_token(self.api_token, self.api_secret)
# Set up API
self.api = API(auth)
def send_message(self, use_tco = 'true'):
"""Processes and sends direct message.
parameters:
use_tco -- use the t.co url shortner
"""
self.subject = subject.strip()
self.message = message.strip()
self.url = url.strip()
# Use url t.co url shortner?
if self.tweet != '':
self.tweet = _clean_tweet(use_tco=use_tco or False)
_send_message()
def _send_message(self):
"""Implemets tweepy send direct message.
Note: to is a list of Twitter IDs or Twitter usernames.
Twitter usernames can change, Twitter IDs do not.
"""
# Loop throught the to's
from tweepy.error import TweepError
for t in self.to:
self.api.send_direct_message(user=t, text=self.tweet)
def _clean_tweet(self, use_tco=True):
"""Creates tweets by truncating subject at appropriate length.
Length is calculated using the length of a t.co URL or the provided URL
depending the use_tco parameter.
"""
if use_tco:
length = 160 - 19
tweet = u'%s %s' % self.subject[0:length], self.url
else:
length = 160-len(self.url)-1
tweet = u'%s %s' % self.subject[0:length], self.url
return tweet
def _share(self):
"""Implements "sharing" on twitter which is exactly like tweeting.
Note: Tweeting is the same as "updating your status".
"""
result = self.api.update_status(status=self.tweet)
示例2: TweepyApi
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
#.........这里部分代码省略.........
@to_direct_message
@include_entities
def get_direct_messages(self, **kwargs):
dms = self._api.direct_messages(**kwargs)
sent = self._api.sent_direct_messages(**kwargs)
dms.extend(sent)
return dms
# NOTE:
# `get_thread` is not decorated with `to_status` because
# it uses `TweepyApi.get_user_timeline` which is already
# decorated
@include_entities
def get_thread(self, status, **kwargs):
"""
Get the conversation to which `status` belongs.
It filters the last tweets by the participanting users and
based on mentions to each other.
"""
author = status.authors_username
mentioned = status.mentioned_usernames
if author not in mentioned:
mentioned.append(author)
tweets = []
for username in mentioned:
tweets.extend(self.get_user_timeline(username, **kwargs))
def belongs_to_conversation(status):
for username in mentioned:
if username in status.text:
return True
return filter(belongs_to_conversation, tweets)
@to_status_from_search
@include_entities
def search(self, text, **kwargs):
return self._api.search(text, **kwargs)
def update(self, text):
self._api.update_status(text)
def destroy_status(self, status):
self._api.destroy_status(status.id)
def retweet(self, status):
self._api.retweet(status.id)
def direct_message(self, username, text):
self._api.send_direct_message(user=username, text=text)
def destroy_direct_message(self, dm):
self._api.destroy_direct_message(dm.id)
def create_friendship(self, screen_name):
self._api.create_friendship(screen_name=screen_name)
def destroy_friendship(self, screen_name):
self._api.destroy_friendship(screen_name=screen_name)
def create_favorite(self, status):
self._api.create_favorite(status.id)
def destroy_favorite(self, status):
self._api.destroy_favorite(status.id)
# list methods
def get_lists(self, screen_name):
raise NotImplementedError
def get_own_lists(self):
raise NotImplementedError
def get_list_memberships(self):
raise NotImplementedError
def get_list_subscriptions(self):
raise NotImplementedError
def get_list_timeline(self, list):
raise NotImplementedError
def get_list_members(self, list):
raise NotImplementedError
def is_list_member(self, user, list):
raise NotImplementedError
def subscribe_to_list(self, list):
raise NotImplementedError
def get_list_subscribers(self, list):
raise NotImplementedError
def is_list_subscriber(self, user, list):
raise NotImplementedError
示例3: tweet
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def tweet(title, url, location=None, parsed_location=None, username=None):
auth = OAuthHandler(app.config["TWITTER_CONSUMER_KEY"], app.config["TWITTER_CONSUMER_SECRET"])
auth.set_access_token(app.config["TWITTER_ACCESS_KEY"], app.config["TWITTER_ACCESS_SECRET"])
api = API(auth)
urllength = 23 # Current Twitter standard for HTTPS (as of Oct 2014)
maxlength = 140 - urllength - 1 # == 116
if username:
maxlength -= len(username) + 2
locationtag = u""
if parsed_location:
locationtags = []
for token in parsed_location.get("tokens", []):
if "geoname" in token and "token" in token:
locname = token["token"].strip()
if locname:
locationtags.append(u"#" + locname.title().replace(u" ", ""))
locationtag = u" ".join(locationtags)
if locationtag:
maxlength -= len(locationtag) + 1
if not locationtag and location:
# Make a hashtag from the first word in the location. This catches
# locations like 'Anywhere' which have no geonameid but are still valid
locationtag = u"#" + re.split("\W+", location)[0]
maxlength -= len(locationtag) + 1
if len(title) > maxlength:
text = title[: maxlength - 1] + u"…"
else:
text = title[:maxlength]
text = text + " " + url # Don't shorten URLs, now that there's t.co
if locationtag:
text = text + " " + locationtag
if username:
text = text + " @" + username
api.update_status(text)
示例4: TwitterPlayer
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class TwitterPlayer(player.Player):
def __init__(self, model, code, access_token, access_token_secret, opponent):
player.Player.__init__(self, model, code)
self._opponent = opponent
self._last_id = None
self._auth = OAuthHandler(auth.consumer_key, auth.consumer_secret)
self._auth.set_access_token(access_token, access_token_secret)
self._api = API(self._auth)
self._listener = TwitterListener(self, self._api)
self._stream = Stream(self._auth, self._listener)
@property
def username(self):
return self._auth.get_username()
def allow(self):
print 'This is the opponent\'s turn...'
self._stream.userstream()
def update(self, event):
if event.player == self.code:
return
message = '@%s %s' % (self._opponent, self._model.events[-1][1])
self.tweet(message)
def tweet(self, message):
if self._last_id is None:
self._api.update_status(message)
else:
self._api.update_status(message, self._last_id)
示例5: tweet
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def tweet(title, url, location=None, parsed_location=None):
auth = OAuthHandler(app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(app.config['TWITTER_ACCESS_KEY'], app.config['TWITTER_ACCESS_SECRET'])
api = API(auth)
urllength = 23 # Current Twitter standard for HTTPS (as of Oct 2014)
maxlength = 140 - urllength - 1 # == 116
locationtag = u''
if parsed_location:
locationtags = []
for token in parsed_location.get('tokens', []):
if 'geoname' in token and 'token' in token:
locname = token['token'].strip()
if locname:
locationtags.append(u'#' + locname.title().replace(u' ', ''))
locationtag = u' '.join(locationtags)
if locationtag:
maxlength -= len(locationtag) + 1
if not locationtag and location:
# Make a hashtag from the first word in the location. This catches
# locations like 'Anywhere' which have no geonameid but are still valid
locationtag = u'#' + re.split('\W+', location)[0]
maxlength -= len(locationtag) + 1
if len(title) > maxlength:
text = title[:maxlength-1] + u'…'
else:
text = title[:maxlength]
text = text + ' ' + url # Don't shorten URLs, now that there's t.co
if locationtag:
text = text + ' ' + locationtag
api.update_status(text)
示例6: Twitter
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class Twitter():
def __init__(self, config = None):
auth = OAuthHandler(unicode(config.consumerKey), unicode(config.consumerSecret))
auth.set_access_token(unicode(config.accessToken), unicode(config.accessTokenSecret))
self._api = API(auth)
def tweet(self, message):
self._api.update_status(message.encode('utf-8'))
示例7: send_reply
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def send_reply(tweetID,screen_name):
try:
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = API(auth)
### at this point I've grabbed the tweet and loaded it to JSON...
status_message = "@%s You are not supposed to use such words. @stophatebot " % (screen_name)
api.update_status(status_message, tweetID)
except Exception, e:
print e
示例8: TweetReply
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class TweetReply():
def __init__(self):
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
self.api = API(auth)
def tweet_in_response(self, screen_name, tweet_id, url):
# self.api.update_status("@" + screen_name + " Hi! Could you please click the link to stream your surroundings? " + url, tweet_id)
self.api.update_status("@" + screen_name + " We support you!", tweet_id)
def tweet_to_person(self, screen_name):
# self.api.update_status("@" + screen_name + " Hi! Could you please click the link to stream your surroundings? " + url, tweet_id)
self.api.update_status("@" + screen_name + " Somebody requested a live stream from you: http://streamy.co/streamer/" + screen_name)
示例9: update_status
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def update_status(text):
try:
consumer_key = environ['TWITTER_CONSUMER_KEY']
access_token = environ['TWITTER_ACCESS_TOKEN']
consumer_secret = environ['TWITTER_CONSUMER_SECRET']
access_secret = environ['TWITTER_ACCESS_SECRET']
except KeyError:
error("No Twitter credentials were found.")
# We don't have login stuff, bail.
return
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = API(auth_handler=auth)
api.update_status(status=text)
示例10: testbasicauth
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def testbasicauth(self):
auth = BasicAuthHandler(username, password)
# test accessing twitter API
api = API(auth)
s = api.update_status('test %i' % random.randint(1, 1000))
api.destroy_status(s.id)
示例11: post_to_twitter
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def post_to_twitter(tweet_message="Visit www.vikalpsangam.org"):
keys = open("vikalp/twitter_keys.txt", "r").read().split(',')
try:
api_key = keys[0]
api_secret = keys[1]
oauth_token = keys[2]
oauth_token_secret = keys[3]
auth = OAuthHandler(api_key, api_secret)
auth.set_access_token(oauth_token, oauth_token_secret)
api_stream = API(auth)
api_stream.update_status(tweet_message)
except Exception as e:
print "Exception log: " + str(e)
示例12: Crawler
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class Crawler():
''' The global crawler manager '''
def __init__(self, name):
self.name = name
self.regexp = re.compile(r'@%s\s+' % (self.name),
re.IGNORECASE)
self._start_stream()
def _auth(self):
self.auth = OAuthHandler(Ukey, Usecret)
self.auth.set_access_token(Akey, Asecret)
self.api = API(self.auth)
def _start_stream(self):
self.listener = Streamer(self)
self._auth()
self.stream = Stream(self.auth, self.listener)
self.stream.userstream()
def on_request(self, text, author):
text = re.sub(self.regexp, '', text)
text = re.sub(r'\s+$', '', text)
lang = get_language(text, key=u'startword')
if lang is not None:
core = Core(lang)
self.send_message(core.send_message(), author)
def send_message(self, text, target=None):
if(target is not None):
text = u'@%s %s' % (target, text)
print(text)
print '>>>', len(text)
self.api.update_status(text)
示例13: tweet
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
def tweet(title, url, location=None):
auth = OAuthHandler(app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(app.config['TWITTER_ACCESS_KEY'], app.config['TWITTER_ACCESS_SECRET'])
api = API(auth)
maxlength = 120 # 120 chars plus URL = 140 max for Twitter
if location:
# Make a hashtag from the first word in the location
locationtag = '#'+re.split('\W+', location)[0]
maxlength -= len(locationtag)+1
else:
locationtag = None
if len(title) > maxlength:
text = title[:maxlength-3] + '...'
else:
text = title[:maxlength]
text = text + ' ' + shorten(url)
if locationtag:
text = text + ' ' + locationtag
api.update_status(text)
示例14: TwitterAPIBot
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class TwitterAPIBot(object):
"""Bot to operate in Twitter using the API"""
ACCESS_TOKEN = os.environ['TWI_AC_TOKEN']
ACCESS_SECRET = os.environ['TWI_AC_SECRET']
CONSUMER_KEY = os.environ['TWI_CO_KEY']
CONSUMER_SECRET = os.environ['TWI_CO_SECRET']
def sign_in(self):
auth = OAuthHandler(TwitterAPIBot.CONSUMER_KEY,
TwitterAPIBot.CONSUMER_SECRET)
auth.set_access_token(TwitterAPIBot.ACCESS_TOKEN,
TwitterAPIBot.ACCESS_SECRET)
self.api = API(auth)
def tweet(self, text):
self.api.update_status(status=text)
def sign_out(self):
TwitterAPIBot.CONSUMER_KEY, TwitterAPIBot.CONSUMER_SECRET = (None,) * 2
TwitterAPIBot.ACCESS_TOKEN, TwitterAPIBot.ACCESS_SECRET = (None,) * 2
示例15: TwitterWrap
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_status [as 别名]
class TwitterWrap(object):
def __init__(self):
self.auth = OAuthHandler(CONS_KEY, CONS_SECRET)
self.auth.set_access_token(AXS_TKN, AXS_TKN_SECRET)
self.twitter = API(self.auth)
def tweet_length_check(self, user_name, tweet_id, haiku):
""""
Makes sure our tweet length is short enough for twitter
"""
p1, p2, p3 = haiku
tweet = "A #haiku: https://twitter.com/%s/status/%s\n\n%s\n%s\n%s" % (user_name, tweet_id, p1, p2, p3)
return tweet
def tweet(self, _string):
"""Updates the status of the twitter user, then sleeps for a random
amount of time to avoid getting blocked by the API"""
sleeptime1 = random.random()
sleeptime2 = random.randint(0,50)
print "Sleeping for " + str(sleeptime1 + sleeptime2)
sleep(sleeptime1 + sleeptime2)
self.twitter.update_status("%s" % (_string))
def debug_tweet(self, tweet, to_tweet, word_val_list):
"""Prints out the information about a tweet"""
template = "{0:30}{1:5}{2:5}{3:5}"
print "ORIGINAL TWEET::"
print tweet['text']
print "BY::"
print tweet['user']['screen_name']
print "PARSED VERSION::"
print to_tweet
print "length %i" % len(to_tweet)
print "Number of syllables in each word in the tweet..."
print template.format(" ", ' DIC', ' ALG', ' Best')
for count, val in enumerate(word_val_list):
print template.format(*val)