本文整理汇总了Python中twython.Twython.update_status方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.update_status方法的具体用法?Python Twython.update_status怎么用?Python Twython.update_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.update_status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: twitter
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def twitter(self,event=NONE):
try:
tweetStr = ("HURDACI SOSYAL SORUMLULUK PROJESINI KULLANDIGIN ICIN TESEKKUR EDERIZ"+'%s' % (self.E1.get()))
apiKey = '*******************'
apiSecret = '***************************'
accessToken = '**********************************'
accessTokenSecret = '******************************'
api = Twython(apiKey,apiSecret,accessToken,accessTokenSecret)
if len(tweetStr)<= 140:
api.update_status(status=tweetStr)
print "twit atildi"
tweetStr = tweetStr + "s"
print "len: ",len(tweetStr)
self.showMessage("Tesekkurler", "Twit Basari Ile Atildi",2)
self.clear_text()
else:
print "140 karakter sorunu"
self.showMessage("hata", "Twitter 140 Karakter Sinirini Astiniz",1)
self.clear_text()
return "1"
except TwythonError as e:
print "Error Gelmedimi: ", e
self.showMessage("hata", "Ayni twiti bir kere atabilirsiniz.",1)
self.clear_text()
return "0"
开发者ID:zafersn,项目名称:raspberrypi-python-tweet_atma-tkinter_g-rsel_aray-z-mysql_islemeri,代码行数:27,代码来源:twitterandserialReadFullBittiThread.py
示例2: step2
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def step2(self):
print("Step2")
self.set_header("Access-Control-Allow-Origin",origin)
self.set_header("Access-Control-Allow-Headers",'Authorization')
self.set_header("Access-Control-Allow-Credentials","true")
print("Step2")
oauth_token = self.get_argument("oauth_token")
oauth_verifier = self.get_argument("oauth_verifier")
print("Step 2: oauth_token: " + oauth_token)
print("Step 2: oauth_verifier: " + oauth_verifier)
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
global twitter
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(oauth_verifier)
OAUTH_TOKEN = final_step['oauth_token']
OAUTH_TOKEN_SECRET = final_step['oauth_token_secret']
print(OAUTH_TOKEN)
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
screen_name = twitter.verify_credentials()["screen_name"]
twitter.update_status(status='Hello!')
self.write(screen_name)
示例3: generate_graphs
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def generate_graphs():
for pair_config in KEYS:
media_ids = []
tweet = ''
for interval in ['day', 'week', 'month', 'year']:
text = output_graph(interval, pair_config)
if not text:
continue
tweet += text
if args.tweeting and pair_config['APP_KEY']:
twitter = Twython(pair_config['APP_KEY'], pair_config['APP_SECRET'],
pair_config['OAUTH_TOKEN'], pair_config['OAUTH_TOKEN_SECRET'])
photo = open('{0}-{1}.png'.format(interval, pair_config['screen_name']), 'rb')
try:
response = twitter.upload_media(media=photo)
except TwythonError:
client.captureException()
return True
media_ids += [response['media_id']]
time.sleep(10)
if args.tweeting and pair_config['APP_KEY']:
twitter = Twython(pair_config['APP_KEY'], pair_config['APP_SECRET'],
pair_config['OAUTH_TOKEN'], pair_config['OAUTH_TOKEN_SECRET'])
try:
for status in twitter.get_user_timeline(screen_name=pair_config['screen_name']):
twitter.destroy_status(id=status['id_str'])
twitter.update_status(status=tweet, media_ids=media_ids)
except TwythonError:
client.captureException()
示例4: tweet
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def tweet():
with open(file_name) as file:
accounts = file.readlines()
if len(accounts) == 0:
print 'no accounts. Please add an account before tweeting'
else:
has_media = raw_input('Does the tweet you want to post contains any media file?\ny: yes\nn: no\n')
media_path = None
if has_media is 'y':
media_path = raw_input('Paste the path to your media file here\n').rstrip(' \r\n')
for account in accounts:
screen_name = account.split(',')[0]
oauth_token = account.split(',')[1]
oauth_token_secret = account.split(',')[2].rstrip('\n')
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
tweet_text = raw_input('Type in the text of tweet for account ' + screen_name + '\n')
if media_path is not None:
media = open(media_path, 'rb')
response = twitter.upload_media(media = media)
try:
twitter.update_status(status = tweet_text, media_ids=[response['media_id']])
print ('tweet for account ' + screen_name + ' posted')
except TwythonError as error:
print (error)
else:
try:
twitter.update_status(status = tweet_text)
print ('tweet for account ' + screen_name + ' posted')
except TwythonError as error:
print (error)
示例5: post_social_media
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def post_social_media(user_social_auth, social_obj):
message = social_obj.create_social_message(user_social_auth.provider)
link = social_obj.url()
if user_social_auth.provider == 'facebook':
if settings.USE_FACEBOOK_OG:
post_to_facebook_og(settings.SOCIAL_AUTH_FACEBOOK_APP_TOKEN, user_social_auth, social_obj)
else:
post_to_facebook(settings.SOCIAL_AUTH_FACEBOOK_APP_TOKEN, user_social_auth, message, link)
elif user_social_auth.provider == 'twitter':
twitter = Twython(
app_key=settings.SOCIAL_AUTH_TWITTER_KEY,
app_secret=settings.SOCIAL_AUTH_TWITTER_SECRET,
oauth_token=user_social_auth.tokens['oauth_token'],
oauth_token_secret=user_social_auth.tokens['oauth_token_secret']
)
full_message_url = "{0} {1}".format(message, link)
# 140 characters minus the length of the link minus the space minus 3 characters for the ellipsis
message_trunc = 140 - len(link) - 1 - 3
# Truncate the message if the message + url is over 140
if len(full_message_url) > 140:
safe_message = "{0}... {1}".format(message[:message_trunc], link)
else:
safe_message = full_message_url
twitter.update_status(status=safe_message, wrap_links=True)
示例6: tweetGif
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def tweetGif(filename, quote):
reduceGif(filename)
try:
response = requests.post(
url,
headers = headers,
data = {
'key': API_KEY,
'image': b64encode(open(filename, 'rb').read()),
'type': 'base64',
'name': filename,
'title': 'random dot gif'
}
)
except requests.exceptions.ConnectionError:
# try again.
tweetGif(filename, quote)
try:
res_json = response.json()
link = res_json['data']['link']
except ValueError:
# try again.
tweetGif(filename, quote)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
status = '"' + quote + '" ' + link + ' #randomgif'
twitter.update_status(status=status)
示例7: send
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def send(message, picture):
# Build Twython API
api = Twython(settings.CONSUMER_KEY,
settings.CONSUMER_SECRET,
settings.ACCESS_KEY,
settings.ACCESS_SECRET)
#time_now = time.strftime("%H:%M:%S") # get current time
#date_now = time.strftime("%d/%m/%Y") # get current date
#tweet_txt = "Photo captured by @twybot at " + time_now + " on " + date_now
try:
# Send text message with picture
if picture is not None:
media_status = api.upload_media(media=picture)
api.update_status(media_ids=[media_status['media_id']], status=message)
# Send text message
else:
api.update_status(status=message)
except TwythonError, error:
print error
示例8: __init__
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
class TwitterCommands:
"""
Commands that will be executed when a user executes a voice command on the Cocoa application
"""
def __init__(self):
#app key, secret, oauth token, oauth secret. modify
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_SECRET = ''
self.twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_SECRET)
self.twitter.verify_credentials()
def send_tweet(self, tweet):
self.twitter.update_status(status=tweet)
def update_avatar(self, file_path):
avatar = open(file_path, 'rb')
self.twitter.update_profile_image(image=avatar)
def search_twitter(self, keywords):
search_dict = self.twitter.search(q=keywords, result_type='popular')
for elem in search_dict['statuses']:
print elem['text']
def tweet_image(self, file_path, message):
photo = open(file_path, 'rb')
self.twitter.update_status_with_media(status=message, media=photo)
示例9: Uploader
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
class Uploader(object):
def __init__(self, folder="."):
self.folder = folder
self.already_uploaded_file = "uploaded.txt"
self.already_uploaded = []
self.image_format_extension = ".jpg"
# Uncomment and fill with your details
# app_key = "your key"
# app_secret = "your secret"
# oauth_token = "your otoken"
# oauth_token_secret = "your osecret"
self.twitter = Twython(app_key=app_key,
app_secret=app_secret,
oauth_token=oauth_token,
oauth_token_secret=oauth_token_secret)
self.load_already_uploaded()
def upload(self, new_file):
if not self.is_already_uploaded(new_file):
with open(new_file, "rb") as image:
image_ids = self.twitter.upload_media(media=image)
self.twitter.update_status(status="hello this is a status #testing_smth",
media_ids=[image_ids["media_id"]])
self.write_to_uploaded(new_file=new_file)
return True
else:
print "Already uploaded!"
return False
def load_already_uploaded(self):
try:
with open(self.already_uploaded_file, "r") as log_file:
con = log_file.read()
self.already_uploaded = [x.strip() for x in con.split("\n")]
except IOError as err:
pass
def write_to_uploaded(self, new_file):
with open(self.already_uploaded_file, "a+") as log_file:
log_file.write("{0}\n".format(new_file))
self.load_already_uploaded()
def is_already_uploaded(self, new_file):
self.load_already_uploaded()
if new_file.strip() in self.already_uploaded:
return True
return False
def run_watcher(self):
try:
while "pigs" != "fly":
all_files = os.listdir(self.folder)
for f in all_files:
if f.endswith(self.image_format_extension):
if self.upload(new_file=os.path.join(self.folder, f)):
print "Uploaded '{0}'".format(f)
time.sleep(1)
except KeyboardInterrupt as err:
print "Thank you Exiting..."
示例10: send_tweet
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def send_tweet(message,status_id):
twitter = Twython(config.APP_KEY, config.APP_SECRET, config.OAUTH_TOKEN, config.OAUTH_TOKEN_SECRET)
try:
twitter.update_status(status=message, in_reply_to_status_id=status_id)
except:
return False
return True
示例11: tweet_current_weather
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def tweet_current_weather(debug=False):
tweet = get_tweet()
if debug:
print(tweet)
else:
twitter = Twython(API_KEY, API_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
twitter.update_status(status=tweet)
示例12: tweet_string
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def tweet_string(message, log, media=None):
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
retries = 0
while retries < 5:
log.setLevel(logging.ERROR)
try:
if media:
photo = open(media, 'rb')
media_ids = twitter.upload_media(media=photo)
twitter.update_status(status=message.encode('utf-8').strip(), media_ids=media_ids['media_id'])
else:
twitter.update_status(status=message.encode('utf-8').strip())
break
except TwythonAuthError, e:
log.setLevel(old_level)
log.exception(" Problem trying to tweet string")
twitter_auth_issue(e)
return
except:
示例13: get
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def get(self):
idnum = 0
lastTweet = db.GqlQuery("SELECT * FROM LastTweet").fetch(1)[0]
# try:
# lastTweet = LastTweet.all()
# except:
# lastTweet = None
# if lastTweet != None:
# idnum = lastTweet.tweetId
# else:
# idnum = "0"
apiKey = '*****'
apiSecret = '******'
accessToken = '******'
accessTokenSecret = '******'
twitter = Twython(apiKey,apiSecret,accessToken,accessTokenSecret)
message = "This book can help improve vocabulary in a natural manner. Its available on Kindle http://goo.gl/Wrrydb"
search_results = twitter.search(q="your_search_query", since_id = idnum, count=20)
print(search_results)
for tweet in search_results["statuses"]:
screenname = "@" + tweet["user"]["screen_name"]+" ";
print tweet["id_str"]
try:
#self.response.write('Hello world!')
twitter.update_status(status=screenname + message, in_reply_to_status_id=tweet["id_str"])
except TwythonError:
pass
idnum = tweet["id_str"]
print(idnum)
if search_results:
lastTweet.tweetId = idnum
lastTweet.put()
示例14: tweet_status
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def tweet_status():
#prep for tweet
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_TOKEN = keys['access_token']
ACCESS_TOKEN_SECRET = keys['access_token_secret']
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
#query data for last hour
con = psycopg2.connect(database=db, user=user, host=host, port=5432)
cur = con.cursor()
cur.execute(open("/home/ec2-user/niceridestatus/code/select_hour_stats.sql").read())
q = cur.fetchall()
r_list = []
for el in q[0]:
r_list.append(el)
status_text = "In the past hour, there were an avg %s #NiceRideMN bikes avail in #Minneapolis, %s in #StPaul, and %s elsewhere" % ("{:,.0f}".format(r_list[0]), "{:,.0f}".format(r_list[1]), "{:,.0f}".format(r_list[2]))
try:
# print status_text
twitter.update_status(status=status_text)
except TwythonError as e:
print "failed to tweet"
print e
pass
示例15: post_to_twitter
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status [as 别名]
def post_to_twitter(sender, instance, *args, **kwargs):
APP_KEY = "vzbqdzbtpCKoa5dbHw1JGwv2i"
APP_SECRET = "Uc3Fi50PPb7f2j2JWO90VqQF5pocfuBiPzppl5E4Y5AaqLteNQ"
twitter = Twython(APP_KEY, APP_SECRET, instance.user.Token_Auth, instance.user.Token_Auth_Secret)
twitter.update_status(status=instance.get_twitter_message())