当前位置: 首页>>代码示例>>Python>>正文


Python Twython.update_status_with_media方法代码示例

本文整理汇总了Python中twython.Twython.update_status_with_media方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.update_status_with_media方法的具体用法?Python Twython.update_status_with_media怎么用?Python Twython.update_status_with_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twython.Twython的用法示例。


在下文中一共展示了Twython.update_status_with_media方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: shareTwitterPost

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def shareTwitterPost(appId):
    appDetails = getTwitterAppDetailsById(appId)
    twitterAgent = Twython(twitterConstants.CONSUMER_KEY, twitterConstants.CONSUMER_SECRET,
                           session["twitter_user_token"],
                           session["twitter_user_secret"])
    twitterAgent.update_status_with_media(status=common.baseUrl + url_for('/facebook/appDetails/', appId=appId),
                                          media=photo(appDetails.AppResultImage))
开发者ID:tharinda221,项目名称:product-JSApps,代码行数:9,代码来源:twitter.py

示例2: ColoursBot

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
class ColoursBot(object):
    
    def __init__(self, keys=const.keys, size=200,
                 ncolour = number_of_colours,
                 fileloc=os.path.dirname(__file__)+'/colors_simp_with_link.txt'):
        try:
            self.api = Twython(keys['api_key'],keys['api_secret'],
                          keys['access_token'], keys['access_token_secret'])
        except Exception as e:
            print("An error occured in initialization.\n{}".format(e))
        
        self.ncolour=ncolour
        self.fileloc=fileloc
        self.size=size
        with open(fileloc, 'r') as f:
            self.colors = list(map(Colour.from_string,f))

    def pick_colour(self):
        if is_morning():
            colors = list(filter(lambda c: c.is_light(), self.colors))
        else:
            colors = self.colors
        n_max = len(colors)
        return colors[randint(0,n_max-1)]
    
    def update(self):
        c = self.pick_colour()
        text = c.to_string()
        picdata = c.to_image(self.size)
        # https://twython.readthedocs.org/en/latest/usage/advanced_usage.html
        self.api.update_status_with_media(
            status=text, media=picdata)
        return c
开发者ID:lesguillemets,项目名称:gae_twbots,代码行数:35,代码来源:colors.py

示例3: __init__

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [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)
开发者ID:vraja2,项目名称:fb-twitter-voice-recognition,代码行数:30,代码来源:twitter_commands.py

示例4: tweet_image

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def tweet_image(account, tweet, image):
# Tweet an image to a twitter account associated with pre-recorded
# API details. The location of these details is provided by the
# account parameter. The image must be within the current directory
# and saved as a .jpg

	fileName = account + ".dat"

	load_file = open(fileName,'rb')
	load_data = pickle.load(load_file)
	load_file.close()	

	#load image
	image = image + '.jpg'
	i = open(image,'rb')

	#consumer keys relate to the app, access keys to the account
	CONSUMER_KEY = load_data['itemOne']
	CONSUMER_SECRET = load_data['itemTwo']
	ACCESS_KEY = load_data['itemThree']
	ACCESS_SECRET = load_data['itemFour']

	#save above details to single variable
	api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
	
	#post tweet & image parameter contents
	api.update_status_with_media(status = tweet, media = i)
开发者ID:DaxMoonJuice,项目名称:pangolin_pad,代码行数:29,代码来源:twitter.py

示例5: POST

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
 def POST(self):
     x = web.input(myfile={}, share=None)
     filedir = "/home/ubuntu/uploads"  # change this to the directory you want to store the file in.
     if "myfile" in x:  # to check if the file-object is created
         filepath = x.myfile.filename.replace("\\", "/")  # replaces the windows-style slashes with linux ones.
         filename = filepath.split("/")[-1]
         filename = str(time.time()) + filename
         im = Image.open(x.myfile.file)  # writes the uploaded file to the newly created file.
         size = 700, 700
         im.thumbnail(size, Image.ANTIALIAS)
         im.save(filedir + "/" + filename, "JPEG")
         cookies = web.cookies()
         OAUTH_TOKEN = cookies.OAUTH_TOKEN
         OAUTH_TOKEN_SECRET = cookies.OAUTH_TOKEN_SECRET
         twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
         names = twitter.verify_credentials()
         print names
         db.insert(
             "posts",
             description=x.description,
             url="/robogram/static/uploads/" + filename,
             tags=x.tags,
             username=names["screen_name"],
         )
         if x.share:
             photo = open(filedir + "/" + filename, "rb")
             twitter.update_status_with_media(
                 status="Hey, just posted a pic at Robogram! " + x.description, media=photo
             )
     raise web.seeother("/upload")
开发者ID:phckopper,项目名称:robogram,代码行数:32,代码来源:code.py

示例6: TwitterCam

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
class TwitterCam(object):
	def __init__(self, a_animated):
		self.twitter_obj = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
		self.animated = a_animated

	@property
	def command(self):
		command = 'sh take_picture.sh'.split()
		if self.animated:
			command.append('-a')
		return command

	@property
	def fileName(self):
		if self.animated:
			return 'output.gif'
		else:
			return 'output.jpg'

	def tweet(self):
		print 'capturing...'
		subprocess.check_output(self.command)
		print 'capture done!'
		print 'uploading...'
		ouputFile = open(self.fileName, 'rb')
		self.twitter_obj.update_status_with_media(status='Testing: using rPi GPIO input (animated:'+str(self.animated)+')', media=ouputFile)
		print "done uploading!"

	def test(self):
		print self.command;
开发者ID:joecabezas,项目名称:PascalElGatito,代码行数:32,代码来源:TwitterCam.py

示例7: __init__

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
class TwitterPyThalesians:

    def __init__(self, *args, **kwargs):
        self.logger = LoggerManager().getLogger(__name__)

    def set_key(self, APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET):
        self.twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

    def auto_set_key(self):
        self.twitter = Twython(Constants().APP_KEY, Constants().APP_SECRET,
                               Constants().OAUTH_TOKEN, Constants().OAUTH_TOKEN_SECRET)

    def update_status(self, msg, link = None, picture = None):
        # 22 chars URL
        # 23 chars picture

        chars_lim = 140

        if link is not None: chars_lim = chars_lim - (22 * link)
        if picture is not None: chars_lim = chars_lim - 23

        if (len(msg) > chars_lim):
            self.logger.info("Message too long for Twitter!")

        if picture is None:
            self.twitter.update_status(status=msg)
        else:
            photo = open(picture, 'rb')
            self.twitter.update_status_with_media(status=msg, media=photo)
开发者ID:BryanFletcher,项目名称:pythalesians,代码行数:31,代码来源:twitterpythalesians.py

示例8: TweetThread

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
class TweetThread(threading.Thread):

    def __init__(self,message):
        super(TweetThread,self).__init__()
        self.message = message
        self.twitter = Twython(
            #consumer key
            "fF86BdSdopE9FAES5UNgPw",
            #consumer secret
            "n7G4K80kYQ6NDMQiYn3GY5Hyk82fF2So17Nl1UQdGWE",
            #access_token
            "1336977176-4CgpPJnJBx7kCRqnwLcRbXI3nLpHj44sp3r2bXy",
            #access_token_secret
            "5rLNvZm3JZdkx0K1Jx9jgsqMG6MmGLAQmPdJ7ChtzA",
        )

    def run(self):
        #send a picture tweet
        print("sending a tweet with an image...")
        photo = open('mugshot.jpg', 'rb')
        try:
            self.twitter.update_status_with_media(media=photo, status=self.message)
            print("sent")
        except:
            print("twython problem")
开发者ID:mattvenn,项目名称:the-waggler,代码行数:27,代码来源:twitter.py

示例9: __init__

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
	def __init__(self,text='',image=False,file_photo='/var/www/foto.jpg'):
		CONSUMER_KEY = 'TPcId3ZdR7jCYwec1A'
		CONSUMER_SECRET = '5eY3k8mEpHI0wCD2LSFK4y2b4zlMunbfc9zpEjdNU'
		ACCESS_KEY = '2273997643-dqvuxb4B2oOm2bFE0TKKMjXzt7vfCF7DZgy1HcW'
		ACCESS_SECRET = 'W9LcdB5qRh2dvWjbzR0C366nYQRPZq8f5RTOdvCZKuxFq'

		if(rpi_device):
			api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
			
			if(text==''):
				date = datetime.datetime.now()
				text = date.strftime('%d %b %Y  %I:%M')

			if(image):	
				photo = open(file_photo,'rb')
				try:
					api.update_status_with_media(media=photo, status=text)
				except TwythonError as e:
					logging.error(e)

			else : 
				try:
					api.update_status_with_media(status=text)
				except TwythonError as e:
					logging.error(e)					
				
			logging.info('Tweet sent')
		else : logging.error('Twython lib not found')
开发者ID:mjalvar,项目名称:framework,代码行数:30,代码来源:Tweet.py

示例10: post2twitter

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def post2twitter(pathString, msg):		        # Twitter Post with Image

    photo = open(pathString, 'rb')                      # Open the file to be posted

    # Send to twitter with message and image
    twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,OAUTH_TOKEN,OAUTH_SECRET) # Authenticate
    twitter.update_status_with_media(media=photo, status=msg)               # Post
开发者ID:DynamoBen,项目名称:Wirecast,代码行数:9,代码来源:WCsnap2social.py

示例11: callback

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def callback(photolog_id):
    """ twitter로부터 callback url이 요청되었을때 
        최종인증을 한 후 트위터로 해당 사진과 커멘트를 전송한다.  
    """

    Log.info("callback oauth_token:" + request.args['oauth_token']);
    Log.info("callback oauth_verifier:" + request.args['oauth_verifier']);
    
    # oauth에서 twiter로 부터 넘겨받은 인증토큰을 세션으로 부터 가져온다.
    OAUTH_TOKEN        = session['OAUTH_TOKEN']
    OAUTH_TOKEN_SECRET = session['OAUTH_TOKEN_SECRET']
    oauth_verifier     = request.args['oauth_verifier']
    
    # 임시로 받은 인증토큰을 이용하여 twitter 객체를 만들고 인증토큰을 검증한다.     
    twitter = Twython(current_app.config['TWIT_APP_KEY'], 
                      current_app.config['TWIT_APP_SECRET'], 
                      OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
    final_step = twitter.get_authorized_tokens(oauth_verifier)    
    
    # oauth_verifier를 통해 얻은 최종 인증토큰을 이용하여 twitter 객체를 새로 생성한다.
    twitter = Twython(current_app.config['TWIT_APP_KEY'], 
                      current_app.config['TWIT_APP_SECRET'], 
                      final_step['oauth_token'], 
                      final_step['oauth_token_secret'])
    session['TWITTER'] = twitter

    # 파라미터로 받은 photolog_id를 이용하여 해당 사진과 커멘트를 트위터로 전송한다.
    photo_info = get_photo_info(photolog_id)
    download_filepath = photo_info[2]
    photo_comment = photo_info[3]
    photo = open(download_filepath, 'rb')
    twitter.update_status_with_media(status=photo_comment, 
                                     media=photo)

    return redirect(url_for('.show_all'))
开发者ID:keatonh,项目名称:photolog,代码行数:37,代码来源:twitter.py

示例12: uploadTwitter

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def uploadTwitter( random_word):
    twitter = Twython(api_key, api_secret,
                      oauth_token, oauth_token_secret)
     
    twitter.verify_credentials()
    #photo = open('C:\Users\Samuel Harper\Documents\GitHub\HourlyArt\HourlyArt\newImage\newImageChanged.jpg', 'rb')
    photo = open('HourlyArt/newImage/newImageChanged.jpg', 'rb')
    twitter.update_status_with_media(status='HourlyArt Post#' + str(post_number) + ' #generative #generativeart' + ' #' + random_word , media=photo)
开发者ID:sampyxis,项目名称:HourlyArt,代码行数:10,代码来源:hourlyArt.py

示例13: tweetme

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def tweetme(text, hashtag, image):

    twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

    text = str(text)+str(hashtag)
    photo = open(image, 'rb')

    twitter.update_status_with_media(status=text, media=photo)
    return
开发者ID:Gitesh,项目名称:qotd-screenshot,代码行数:11,代码来源:ssheet.py

示例14: main

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def main():
	parser = argparse.ArgumentParser()

	parser.add_argument("--images", metavar = "IMAGES", nargs = "+",
					help = "The Catcierge match images to send.")

	parser.add_argument("--consumer_key", metavar = "CONSUMER_KEY", 
					help = "The twitter Consumer Key to use for authentication")

	parser.add_argument("--consumer_secret", metavar = "CONSUMER_KEY",
					help = "The twitter Consumer Secret to use for authentication")

	parser.add_argument("--oauth_token", metavar = "OAUTH_TOKEN",
					help = "Oauth token")

	parser.add_argument("--oauth_token_secret", metavar = "OAUTH_TOKEN_SECRET",
					help = "Ouauth token secret")

	parser.add_argument("--status", metavar = "STATUS", type = int,
					help = "The status of the match, 0 = failure, 1 = success.")

	parser.add_argument("--match_statuses", metavar="MATCHSTATUS", type = float, nargs="+",
					help = "List of statuses for each match", default = [])

	parser.add_argument("--direction", metavar="DIRECTION",
					help = "0 for in, 1 for out, -1 for unknown", default = -1)

	args = parser.parse_args()
	
	twitter = Twython(args.consumer_key, args.consumer_secret, args.oauth_token, args.oauth_token_secret)

	# Merge the images into a 4x4 grid using ImageMagick montage.
	montage_args = "-fill white -background black -geometry +2+2 -mattecolor %s" % ("green" if args.status else "red")
	
	i = 0
	for img in args.images:
		montage_args += ' -frame 2 -label "%s" %s' % (args.match_statuses[i], img)
		i += 1

	comp_img = datetime.datetime.fromtimestamp(int(time.time())).strftime('comp_%Y-%m-%d_%H-%M-%S.jpg')
	montage_args += " %s" % comp_img
	call(["montage"] + montage_args.split(" "))

	img = open(comp_img, 'rb')

	direction = "UNKNOWN"

	try:
		if int(args.direction) == 1:
			direction = "OUT"
		elif int(args.direction) == 0:
			direction = "IN"
	except:
		direction = args.direction.upper()

	twitter.update_status_with_media(status = 'Match: %s\nDirecton: %s\n' % (("OK" if args.status else "FAIL"), direction), media = img)
开发者ID:JoakimSoderberg,项目名称:catcierge,代码行数:58,代码来源:catcierge-twitter.py

示例15: generate_and_post_picture

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_status_with_media [as 别名]
def generate_and_post_picture(msg, key):
	src_file = extract_image(random_cat_url())
	outfile = src_file + ".out"
	proc = subprocess.Popen(["./steg","-e", src_file, outfile, msg, key], stdout=subprocess.PIPE)
	# time.sleep(5)
	proc.wait()

	twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
	photo = open(outfile, 'rb')
	twitter.update_status_with_media(media=photo)
开发者ID:LeoWu343,项目名称:ActionYak1942,代码行数:12,代码来源:twitter_post.py


注:本文中的twython.Twython.update_status_with_media方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。