本文整理汇总了Python中tweepy.API.update_with_media方法的典型用法代码示例。如果您正苦于以下问题:Python API.update_with_media方法的具体用法?Python API.update_with_media怎么用?Python API.update_with_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tweepy.API
的用法示例。
在下文中一共展示了API.update_with_media方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pick_a_pic_from_pixiv
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_with_media [as 别名]
def pick_a_pic_from_pixiv(twitter_api: tweepy.API, id_list):
"""
从P战选取一张图片
:param twitter_api:Twitter API
:param id_list: 图片ID列表
:return:是否成功发送tweet
"""
f = open('pixiv_history', 'r')
history = json.load(f)
f.close()
try:
pick = random.randint(0, len(id_list) - 1)
except Exception as e:
print(e)
return False
while id_list[pick][0] in history:
id_list.remove(id_list[pick])
f = open('pixiv_list', 'w')
json.dump(id_list, f)
f.close()
if len(id_list) == 0:
print('Pictures all sent!')
return False
pick = random.randint(0, len(id_list) - 1)
dl_pic = id_list[pick]
print(dl_pic)
history.append(id_list[pick][0])
id_list.remove(id_list[pick])
f = open('pixiv_history', 'w')
json.dump(history, f)
f.close()
f = open('pixiv_list', 'w')
json.dump(id_list, f)
f.close()
file_name = PixivPicDownloader.download_from_url(p_opener, dl_pic[0])
print(file_name)
if file_name is not None:
try:
twitter_api.update_with_media(filename=file_name,
status=PixivPicDownloader.transform_id_to_url(dl_pic[0]))
except tweepy.TweepError as e:
print(e.reason)
return False
print('tweet sent!')
return True
else:
return False
示例2: make_cloud
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import update_with_media [as 别名]
# go
time = datetime.now().strftime("%Y-%m-%d--%H-%M-%S-%f")
logging.info(" " + time + " --- Making tag clouds")
hashtag_img = make_cloud("hashtag",time,maxsize=60,cutoff=50,layout=2)
tweet_img = make_cloud("tweet",time)
if len(sys.argv) == 2 and sys.argv[1] == 'test':
logging.info(" This is a test, not tweeting images.")
else:
logging.info(" Tweeting images.")
# authorize bot
auth = OAuthHandler(swa.consumer_key, swa.consumer_secret)
auth.set_access_token(swa.access_token, swa.access_token_secret)
api = API(auth)
# send the tweet with photo
if tweet_img:
status = 'top skatewords of the day from %d tweets' % num_tweets
api.update_with_media(tweet_img, status=status)
os.remove(tweet_img)
if hashtag_img:
status = 'top skateboarding hashtags of the day from %d tweets' % num_tweets
api.update_with_media(hashtag_img, status=status)
os.remove(hashtag_img)
logging.info(" Done! \n")