本文整理汇总了Python中twython.Twython.updateStatus方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.updateStatus方法的具体用法?Python Twython.updateStatus怎么用?Python Twython.updateStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.updateStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tweet
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def tweet(dbConn):
text = sample(dbConn)
twitterAppData = json.load(open('twitter.json'))
twitter = Twython(app_key = twitterAppData['app_key'],
app_secret = twitterAppData['app_secret'],
oauth_token = twitterAppData['oauth_token'],
oauth_token_secret = twitterAppData['oauth_token_secret'])
print 'Tweet at %s\t%s' % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), text)
twitter.updateStatus(status=text)
示例2: updateTwitterStatus
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def updateTwitterStatus(status, dry_run=False):
twitter = Twython(
twitter_token=TWITTER_TOKEN,
twitter_secret=TWITTER_SECRET,
oauth_token=OAUTH_TOKEN,
oauth_token_secret=OAUTH_SECRET,
)
if dry_run:
return twitter
twitter.updateStatus(status=status)
示例3: post
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def post(self):
username = self.request.get('username', None)
if username is None:
return
twitter = Twython(
twitter_token = CONSUMER_KEY,
twitter_secret = CONSUMER_SECRET,
oauth_token = KRWL_OAUTH_TOKEN,
oauth_token_secret = KRWL_OAUTH_TOKEN_SECRET,
)
status = '@%s your page is ready http://cerewt.appspot.com/user/%s' \
% (username, username)
twitter.updateStatus(status=status)
示例4: FreeBreanna
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
class FreeBreanna(object):
def __init__(self, f='nagged'):
"f is db filename"
self.t = Twython(app_key=auth.app_key,
app_secret=auth.app_secret,
oauth_token=auth.oauth_token,
oauth_token_secret=auth.oauth_token_secret)
self.s = shelve.open(f)
if 'users' not in self.s:
self.s['users'] = []
self.s['lastid'] = None
self.s['count'] = 0
def savetheworld(self):
f = self.t.search(q="-breanna bradley manning", since_id=self.s['lastid'], rpp=100)
if not f['results']:
time.sleep(60*5) #5 min sleep
self.savetheworld()
for i in [Tweet(x['from_user'], x['id']) for x in f['results']]:
print i
if i.user not in self.s['users']:
self.send_reply(i)
time.sleep(15)
self.s['users'].append(i.user)
self.s['lastid'] = sorted([(x['id']) for x in f['results']])[-1]
time.sleep(60*4) #4 minute sleep
self.savetheworld()
def send_reply(self, i):
text = "@%s http://feministing.com/2011/12/22/why-does-the-media-and-her-supposed-supporters-continue-to-misgender-breanna-manning/ #freepvtmanning" % str(i.user)
self.t.updateStatus(status=text,
in_reply_to_status_id=str(i.twid),
lat="39.374325",
long="-94.940114",
display_coordinates= "true")
#https://en.wikipedia.org/wiki/Midwest_Joint_Regional_Correctional_Facility
def islimited(self):
if self.s['count'] < 900:
return False
if 'limitday' in self.s:
if self.s['limitday'].day is not datetime.now().day:
return False
elif self.s['count'] >= 900:
return True
if self.s['count'] >= 900:
return True
示例5: new_campaign
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def new_campaign(request):
context = RequestContext(request)
if request.POST:
post_data = {}
# for k in request.POST.keys():
# post_data[k] = request.POST[k]
# print post_data
# post_data["start_time"] = "%s %s" % (post_data["date"] , post_data["time"])
form = forms.CampaignForm(request.POST)
if form.is_valid():
campaign = form.save(commit=False)
campaign.owner = request.user
campaign.save()
twitprof = TwitterProfile.objects.filter(user=request.user)
if twitprof.exists():
twitprof = twitprof[0]
twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET,
twitprof.oauth_token, twitprof.oauth_secret)
full_tweet = "I've just created a new twitter crowd for #%s, join me at http://microwder.com/c/%d" % (campaign.hashtag, campaign.pk)
try:
twitter.updateStatus(status=full_tweet)
except:
import sys
print sys.exc_info()
return redirect("edit_campaign",id=campaign.pk)
else:
form = forms.CampaignForm()
context["form"] = form
context["pill"] = "new_crowd"
return render_to_response("new_campaign.html", context_instance=context)
示例6: tweet
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def tweet():
t = Twython(
app_key=app_key,
app_secret=app_secret,
oauth_token=request.args['oauth'],
oauth_token_secret=request.args['token']
)
status_update = t.updateStatus(status=request.args['status'])
response = jsonify(status_update)
if (request.args['callback']):
response.data = request.args['callback']+"("+response.data+")"
return response
示例7: publish
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
def publish(self):
success = False
error = None
text = self.tweet
if self.twitter_id == None:
text = self.rebrand_tweet()
if text == self.tweet:
moderate, reasons = self.should_we_moderate()
if not moderate:
try:
tw_api = Twython(app_key=config.TWITTER_API_KEY,
app_secret=config.TWITTER_API_SECRET,
oauth_token=config.TWITTER_OAUTH_TOKEN,
oauth_token_secret=config.TWITTER_OAUTH_SECRET)
tweet = tw_api.updateStatus(status=self.tweet)
self.twitter_id = tweet['id_str']
self.needs_moderation = False
self.published_date = datetime.now(timezone(settings.TIME_ZONE))
success = True
except (TwythonError, TwythonRateLimitError, TwythonAuthError):
# pass error information would be better
error = 'api error'
except:
error = 'some other error'
else:
error = 'needs moderation'
if self.moderation_date == None:
self.moderation_date = datetime.now(timezone(settings.TIME_ZONE))
self.moderation_reasons = "\n".join(reasons)
else:
error = 'tweet needs to be changed for branding'
if error != None:
self.for_editors = True
else:
error = 'This is already published'
return success, error, text
示例8: str
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
global rate_reset
global remaining_hits
pp.pprint(results)
if remaining_hits <= 0:
print "hit my limit!"
return
if time.gmtime() > rate_reset:
rates = api.getRateLimitStatus()
remaining_hits = rates['remaining_hits']
rate_reset = rates['reset_time_in_seconds']
print 'Rate limit: ' + str(remaining_hits)
try:
if results.has_key('event'):
if results['event'] == 'follow':
followed(results)
elif results.has_key('entities'):
if results['user']['id_str'] == current_user['id_str']:
return
if results['entities'].has_key('user_mentions'):
for user_mention in results['entities']['user_mentions']:
if user_mention['id_str'] == current_user['id_str']:
mentioned(results)
break
except TwythonError:
api.updateStatus(status='@seepel I encountered an error!')
try:
api.stream({ 'endpoint' : 'https://userstream.twitter.com/1.1/user.json' }, on_results)
except TwythonError:
api.updateStatus(status='@seepel I have crashed!')
示例9: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
start_time = datetime.datetime.now() - datetime.timedelta(minutes=60)
end_time = datetime.datetime.now()
messages = UserMessage.objects.filter(message__campaign__start_time__gte=start_time).filter(message__campaign__start_time__lte=end_time)
print messages
messages = messages.filter(sent=None).order_by("pk")
print messages
for message in messages:
before_10 = datetime.datetime.now() - datetime.timedelta(minutes=10)
if not UserMessage.objects.filter(user=message.user,sent__gte=before_10).exists():
#only send if we haven't sent a message for this user in the past 10 minutes.
# we can tweak this later
twitprof = TwitterProfile.objects.filter(user=message.user)
if twitprof.exists():
twitprof = twitprof[0]
twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET,
twitprof.oauth_token, twitprof.oauth_secret)
full_tweet = "%s #%s" % (message.message.text, message.message.campaign.hashtag)
print "Sending..."
try:
twitter.updateStatus(status=full_tweet)
message.sent = datetime.datetime.now()
message.save()
except:
print sys.exc_info()
示例10: authenticated
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
from twython import Twython
"""
Note: for any method that'll require you to be authenticated (updating
things, etc)
you'll need to go through the OAuth authentication ritual. See the example
Django application that's included with this package for more information.
"""
twitter = Twython()
# OAuth ritual...
twitter.updateStatus(status="See how easy this was?")
示例11: open
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
from twython import Twython
from format_timeline import *
import os
oauth_tokens = open('oauth_tokens','r')
app_key = oauth_tokens.readline()
app_secret = oauth_tokens.readline()
oauth_token = oauth_tokens.readline()
oauth_token_secret = oauth_tokens.readline()
t = Twython(app_key = app_key.strip('\n'), app_secret = app_secret.strip('\n'),
callback_url = 'http://google.com')
auth_props = t.get_authentication_tokens()
print 'Connect to Twitter via: %s' % auth_props['auth_url']
t = Twython(app_key = app_key.strip('\n'), app_secret = app_secret.strip('\n'),
oauth_token = oauth_token.strip('\n'), oauth_token_secret = oauth_token_secret.strip('\n'))
homeTimeline = format_timeline(t.getHomeTimeline())
#print homeTimeline
#update = raw_input('>' )
t.updateStatus(status = update)
示例12: __init__
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
#.........这里部分代码省略.........
self.post = rospy.Service('post_tweet', Post, self.post_cb)
self.retweet = rospy.Service('retweet', Id, self.retweet_cb)
self.follow = rospy.Service('follow', User, self.follow_cb)
self.unfollow = rospy.Service('unfollow', User, self.unfollow_cb)
self.post_dm = rospy.Service('post_dm', DirectMessage, self.post_dm_cb)
self.destroy = rospy.Service('destroy_dm', Id, self.destroy_cb)
self.timeline = rospy.Service(
'user_timeline', Timeline, self.user_timeline_cb)
# Create timers for tweet retrieval. Use oneshot and retrigger
timer_home = rospy.Timer(
rospy.Duration(1), self.timer_home_cb, oneshot = True )
timer_mentions = rospy.Timer(
rospy.Duration(2), self.timer_mentions_cb, oneshot = True )
timer_dm = rospy.Timer(
rospy.Duration(3), self.timer_dm_cb, oneshot = True )
# Tweet callback
def post_cb(self, req):
txt = req.text
rospy.logdebug("Received a tweet: " + txt)
# If only one picture, use twitter upload
if len(req.images) == 1:
path = self.save_image( req.images[0] )
first = True
for tweet in self.split_tweet( txt ):
if (req.reply_id == 0):
if first:
result = self.t.updateStatusWithMedia(
file_ = path, status = tweet )
first = False
else:
result = self.t.updateStatus( status = tweet )
else:
if first:
result = self.t.updateStatusWithMedia( file_ = path,
status = tweet, in_reply_status_id = req.reply_id )
first = False
else:
result = self.t.updateStatus( status = tweet,
in_reply_to_status_id = req.reply_id )
# Check response for each update.
if self.t.get_lastfunction_header('status') != '200 OK':
return None
os.system('rm -f ' + path)
elif len(req.images) != 0:
txt += upload( req.images )
# Publish after splitting.
for tweet in self.split_tweet( txt ):
if (req.reply_id == 0):
result = self.t.updateStatus( status = tweet )
else:
result = self.t.updateStatus(
status = tweet, in_reply_to_status_id = req.reply_id )
if self.t.get_lastfunction_header('status') != '200 OK':
return None
示例13: ConfigParser
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
# -*- coding: utf-8 -*-
from twython import Twython
import sys
import os
from ConfigParser import SafeConfigParser as ConfigParser
# read config
config = ConfigParser()
config.read(os.path.expanduser('~/.tweeetonly'))
CONSUMER_KEY = config.get('tweeetonly', 'consumer_key')
CONSUMER_SECRET = config.get('tweeetonly', 'consumer_secret')
ACCESS_TOKEN = config.get('tweeetonly', 'access_token')
ACCESS_TOKEN_SECRET = config.get('tweeetonly', 'access_token_secret')
argvs = sys.argv
text = argvs[1]
tw = Twython(
twitter_token = CONSUMER_KEY,
twitter_secret = CONSUMER_SECRET,
oauth_token = ACCESS_TOKEN,
oauth_token_secret = ACCESS_TOKEN_SECRET)
tw.updateStatus(status = text)
示例14: find_lines
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
attempt = find_lines(candidate_lines, line_indicies + [i], rhyming_pattern, syllable_pattern)
if attempt:
return attempt
return False
def find_poem(rhyming_pattern, syllable_pattern, indents=None):
line_indicies = find_lines(pronunciated_lines, [], rhyming_pattern, syllable_pattern)
if line_indicies:
out = map(lambda i: printable_lines[i], line_indicies)
if indents:
for i, l in enumerate(out):
out[i] = indents[i] * " " + l
return "/\n".join(out)
limerick_rhyming_pattern = "AABBA"
limerick_syllable_pattern = [[6, 8], [6, 8], [4, 5], [4, 5], [7, 8]]
limerick_indents = [0, 0, 2, 2, 0]
haiku_rhyming_pattern = "ABC"
haiku_syllable_pattern = [[5, 5], [7, 7], [5, 5]]
poem = find_poem(limerick_rhyming_pattern, limerick_syllable_pattern) + "\n" + hashtag
print poem
print
# ==============================================================================
if "--no-confirm" in sys.argv or raw_input("Publish? ") == "yes":
twyt.updateStatus(status=poem)
示例15: upload
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import updateStatus [as 别名]
###################################
# upload to sftp
try:
transport = paramiko.Transport((sftp_host, sftp_port))
transport.connect(username = sftp_username, password = sftp_password)
sftp = paramiko.SFTPClient.from_transport(transport)
localpath = output_path
remotepath = sftp_basepath + "/" + query + "/%s" % output_file
# let user know it's going
print "Uploading %s to %s..." % (output_file, host)
sftp.put(localpath, remotepath)
sftp.close()
transport.close()
except:
status = "Retrieved %d tweets for the %s session, but failed to upload (cc %s) #%s." % (count, today, ccuser, query)
twitter.updateStatus(status=status)
print status
sys.exit()
# let user know we've uploaded
print "Uploaded to %s on %s" % (remotepath, host)
# set www upload url
upload_url = web_base_url + '/%s' % output_file
# change date format
today = date.today()
today = today.strftime("%a %d %b %Y")
# let user know that the raw log has been uploaded
status = "Uploaded %d tweets for the %s session to %s (cc %s) #%s." % (count, today, upload_url, ccuser, query)