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


Python Twython.update_profile_image方法代码示例

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


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

示例1: __init__

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_profile_image [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

示例2: __init__

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

    def __init__(self, name, con_k, con_s, acc_k, acc_s):
        self.name = name
        self.con_k = con_k
        self.con_s = con_s
        self.acc_k = acc_k
        self.acc_s = acc_s
        self.twitter = Twython(self.con_k, self.con_s, self.acc_k, self.acc_s)
        self.last_intervals = []
        self.last_tweet = ''

    def get_dms(self):
        if self.twitter is not None:
            dms = self.twitter.get_direct_messages()
            return dms
        
    def update_image(self):
        if self.twitter is not None:
            with open('zf.png', 'rb') as image_file:
                encoded_string = base64.b64encode(image_file.read())
                results = self.twitter.update_profile_image(image=encoded_string)
                return results

    def change_name(self, name):
        if self.twitter is not None:
            name = name.replace('"','')
            results = self.twitter.update_profile(name=name)
            return results

    def tweet(self, msg):
        if self.twitter is not None:
            # > 140 char detection
            if len(msg) > 140:
                msg = msg[0:139]
            syslog.syslog('%s is tweeting %s' % (self.name, msg))
            try:
                self.twitter.update_status(status=msg)
                self.last_tweet = msg
            except Exception as e:
                syslog.syslog('%s error tweeting -> %s' % (self.name, str(e)))
开发者ID:zmallen,项目名称:flock,代码行数:43,代码来源:ircbot.py

示例3: post_to_twitter

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_profile_image [as 别名]
def post_to_twitter(filename):
    '''
    Posts the actual image to the twitters.
    Requires a keys.json file, with app_key
    '''

    print 'Posting to twitter'
    with open('keys.json') as f:
        keys = eval(f.read())
    
    #Grabs the connection to twitter
    twitter = Twython(keys['app_key'],
                      keys['app_secret'],
                      keys['oauth_token'],
                      keys['oauth_token_secret'])
    
    with open(filename, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
    
    i = twitter.update_profile_image(image=encoded_string)
    print 'Posted!'
开发者ID:theianrobertson,项目名称:profile-pyc,代码行数:23,代码来源:ProfilePicture.py

示例4: RuntimeError

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_profile_image [as 别名]
        priority = 2

    else:
        raise RuntimeError()

    if occurs:
        candidates.append((priority, image))


best = None

for candidate in candidates:
    if best is None or candidate[0] < best[0]:
        best = candidate

if best is None:
    best = (3, config['default_image'])

print(best)

# Twitter

with open(os.path.join(os.path.dirname(__file__), 'credentials.json')) as data_file:
    credentials = json.load(data_file)['twitter']

twitter = Twython(credentials['app_key'], credentials['app_secret'], credentials['oauth_token'], credentials['oauth_token_secret'])


avatar = open(os.path.join(os.path.dirname(__file__), 'img/' + best[1] + '.png'), 'rb')
twitter.update_profile_image(image=avatar)
开发者ID:FlorianCassayre,项目名称:TwitterDynpic,代码行数:32,代码来源:update.py

示例5: TwitterHelper

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

#.........这里部分代码省略.........
        logger.info(result)
        if result["result"]["places"]:
            # for place in result["result"]["places"]:
            #     logger.info(place["full_name"])

            place = result["result"]["places"][0]
            location.place_id_twitter = place["id"]

            return location
        else:
            return None

    @retry(**retry_args)
    def reverse_geocode(self, location):

        result = self.twitter.reverse_geocode(

            max_results=5,
            lat=location.latitude,
            long=location.longitude)
        logger.info(result)
        if result["result"]["places"]:
            # for place in result["result"]["places"]:
            #     logger.info(place["full_name"])

            place = result["result"]["places"][0]
            location.place_id_twitter = place["id"]

            return location
        else:
            return None

    @retry(**retry_args)
    def update_profile_image(self, file_path):
        if file_path:
            logger.info("updating profile image %s" % file_path)
            with open(file_path, 'rb') as file:
                self.twitter.update_profile_image(image=file)

    @retry(**retry_args)
    def update_profile_banner_image(self, file_path):
        if file_path:
            logger.info("updating banner image %s" % file_path)
            with open(file_path, 'rb') as file:
                try:
                    self.twitter.update_profile_banner_image(banner=file)
                except TwythonError as ex:
                    if "Response was not valid JSON" in str(ex):
                        # twython issue i think
                        logger.warning(ex)
                    else:
                        raise

    @retry(**retry_args)
    def update_profile(self, **kwargs):
        return self.twitter.update_profile(**kwargs)

    @retry(**retry_args)
    def get_list_statuses(self, **kwargs):
        return self.twitter.get_list_statuses(**kwargs)

    @retry(**retry_args)
    def get_user_suggestions_by_slug(self, **kwargs):
        return self.twitter.get_user_suggestions_by_slug(**kwargs)

    @retry(**retry_args)
开发者ID:andrewtatham,项目名称:twitterpibot,代码行数:70,代码来源:twitterhelper.py

示例6: tweetAttempt

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import update_profile_image [as 别名]
						tweetAttempt()
						tweeting = False
						INtweetmenu = False
		elif tweetmenu == "Back":
			INtweetmenu = False
  elif menu == "Customize":
	  customizing = True
	  while customizing:
		  customizeMenu = buttonbox(" ", "Customize - Wolf's Den", ["Profile Picture", "Cover Photo", "Background Image", "Back"])
		  if customizeMenu == "Profile Picture":
			  updatePic = True
			  while updatePic:
				  pic = fileopenbox("Select Picture - Wolf's Den", "Update Profile Picture")
				  pic = open(pic, 'r')
				  try:
					t.update_profile_image(image = pic)
					updatePic = False
				  except twython.TwythonError:
					  msgbox(tweetErrors[0], tweetErrors[2], "Try Again!")
				  except twythonTwythonRateLimitError:
					  msgbox(tweetErrors[1], tweetErrors[2], "Okay")
				  else:
					  msgbox("Profile picture updated!", "Wolf's Den", "Okay")
		  elif customizeMenu == "Cover Photo":
			  """
			  In Development
			  ---------------------------------------------
			  #img = open("test.jpg", "rb")
			  #t.update_profile_banner_image(banner = img)
			  ---------------------------------------------
			  """
开发者ID:Altazon97,项目名称:WolfsDen,代码行数:33,代码来源:Wolf's+Den.py

示例7: TweetToImage

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

#.........这里部分代码省略.........
         for mention in data['entities']['user_mentions']:
            if mention['id'] == self.twitter_user_id:
               found_me = True

         if found_me:

            self.tweet(data)


         elif random.choice(range(100)) < 10 and self.is_followed_by(data['user']['id']):

            self.tweet(data)


         else:

            print ' - Skipping tweet ' + data['text'].encode('utf-8') + ' from @' + data['user']['screen_name']


      elif 'event' in data:

         if data['event'] == 'follow' and data['target']['screen_name'] == 'TweetToImage':
            print '--------------------------------------------------------------------------------'
            print data['source']['screen_name'] + ' followed me, following back...'

            time.sleep(2)

            self.twitter.create_friendship(screen_name=data['source']['screen_name'], follow=True)


   def on_error(self, status_code, data):
      print status_code


   def pad_text(self):
      """Pad text to 147 characters"""

      for i in range(147 - len(self.text)):
         self.text += ' '


   def save_image(self):
      """Save image out to disk"""

      self.image_io = StringIO()
      self.image.writePng(self.image_io)
      self.image_io.seek(0)


   def set_pixels_by_text(self):
      """Run through text and generate an image from it"""

      i = 0
      rgb = [0, 0, 0]

      # Get text from somewhere
      if not self.text:
         self.load_text()

      for c in self.text:

         # Every third character write out as a pixel where
         # RGB colors are the three previous character's
         # unicode values
         if i % 3 == 0 and i > 0:
            color = self.image.colorAllocate(tuple(rgb))

            self.image.filledRectangle(self.coords, (self.coords[0] + self.PIXEL, 
                                                     self.coords[1] + self.PIXEL), color)

            self.increment_coords()

         rgb[i % 3] = ord(c)

         i += 1


   def tweet(self, t):
      """Tweet"""

      time.sleep(2)

      print '--------------------------------------------------------------------------------'
      print 'Replying to @' + t['user']['screen_name']
      print t['text'].encode('utf-8')

      self.text = t['text'].encode('utf-8')
      self.build_image()

      try:
         self.image_io.seek(0)
         self.twitter.update_profile_image(image=self.image_io)
         self.image_io.seek(0)
      except:
         print '*** Error uploading new profile image!'


      self.twitter.update_status_with_media(status='@' + t['user']['screen_name'] + ' :)',
                                            in_reply_to_status_id=t['id_str'],
                                            media=self.image_io)
开发者ID:amarriner,项目名称:BooksToPNG,代码行数:104,代码来源:tweet_to_image.py

示例8: Twython

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

# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_profile_image('myImage.png')
开发者ID:stelianfirez,项目名称:twython,代码行数:7,代码来源:update_profile_image.py


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