本文整理汇总了Python中weibopy.api.API.upload方法的典型用法代码示例。如果您正苦于以下问题:Python API.upload方法的具体用法?Python API.upload怎么用?Python API.upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weibopy.api.API
的用法示例。
在下文中一共展示了API.upload方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
class Test(unittest.TestCase):
consumer_key=''
consumer_secret=''
def __init__(self):
""" constructor """
def getAtt(self, key):
try:
return self.obj.__getattribute__(key)
except Exception as e:
print(e)
return ''
def setAccessToken(self, key, secret):
self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
self.auth.setAccessToken(key, secret)
self.api = API(self.auth, source=self.consumer_key)
def basicAuth(self, source, username, password):
self.auth = BasicAuthHandler(username, password)
self.api = API(self.auth,source=source)
def upload(self, filename, message):
status = self.api.upload(filename, status=message)
self.obj = status
id = self.getAtt("id")
text = self.getAtt("text")
self.obj = self.getAtt("user")
profile_image_url = self.getAtt("profile_image_url")
print("upload,id="+ str(id) +",text="+ text +",profile_image_url="+ profile_image_url)
示例2: __init__
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
class Weibo:
def __init__(self):
# 设定网页应用回调页面(桌面应用设定此变量为空)
BACK_URL = ""
# 验证开发者密钥.
auth = OAuthHandler(APP_KEY, APP_SECRET, BACK_URL)
# 设定用户令牌密钥.
auth.setToken(TOKEN_KEY, TOKEN_SECRET)
# 绑定用户验证信息.
self.api = API(auth)
def send(self, message, image_path=None):
try:
if image_path:
self.api.upload(image_path, message)
else:
self.api.update_status(message)
except WeibopError, e:
print e.reason
示例3: __init__
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
class MyWeibo:
def __init__(self,app_key="3146673438",app_secret="f65a02335629c4ff5c4a5314fedfa97f"):
app_key=app_key
app_secret=app_secret
file=open("token","r")
token_key=file.readline()
token_secret=file.readline()
file.close()
auth=OAuthHandler(app_key,app_secret)
auth.setToken(token_key[0:-1],token_secret)
self.api=API(auth)
def upload(self, filename, message):#上传
message = message.encode("utf-8")
try:
self.api.upload(filename, status=message)
except Exception, e:
print e
return False
else:
示例4: __init__
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
class SinaClient:
def __init__(self, key, secret):
self.auth=OAuthHandler(key,secret)
def get_auth_url(self):
return self.auth.get_authorization_url()
def set_access_token(self,token):
key,secret=token.split('|')
self.auth.setToken(key,secret)
self.api=API(self.auth)
def get_access_token(self):
token=self.auth.access_token
return token.key+'|'+token.secret
def set_request_token(self,token):
key,secret=token.split('|')
self.auth.request_token=oauth.OAuthToken(key,secret)
def get_request_token(self):
token=self.auth.request_token
return token.key+'|'+token.secret
def set_verifier(self,verifier):
self.auth.get_access_token(verifier)
self.api=API(self.auth)
def send_msg(self,msg,coord=None):
lat,long=self.get_lat_long(coord)
msg=msg.encode('utf-8')
status=self.api.update_status(status=msg,lat=lat,long=long)
return status
def send_pic(self,msg,pic,coord=None):
lat,long=self.get_lat_long(coord)
msg=msg.encode('utf-8')
status=self.api.upload(pic,status=msg,lat=lat,long=long)
return status
def get_timeline(self):
return self.request(SINA_USER_TIMELINE_URL)
def get_lat_long(self,coord):
if not coord:
return (None,None)
return map(lambda x:str(x),coord)
def get_user(self):
return self.api.verify_credentials()
示例5: press_sina_weibo
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
def press_sina_weibo():
'''''
调用新浪微博Open Api实现通过命令行写博文,功能有待完善
author: socrates
date:2012-02-06
新浪微博:@偶是正太
'''
sina_weibo_config = configparser.ConfigParser()
#读取appkey相关配置文件
try:
sina_weibo_config.readfp(open('sina_weibo_config.ini'))
except ConfigParser.Error:
print ('read sina_weibo_config.ini failed.')
#获取需要的信息
consumer_key = sina_weibo_config.get("userinfo","CONSUMER_KEY")
consumer_secret =sina_weibo_config.get("userinfo","CONSUMER_SECRET")
token = sina_weibo_config.get("userinfo","TOKEN")
token_sercet = sina_weibo_config.get("userinfo","TOKEN_SECRET")
#调用新浪微博OpenApi(python版)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.setAccessToken(token, token_sercet)
api = API(auth)
#通过命令行输入要发布的内容
# weibo_content = raw_input('Please input content:')
# status = api.update_status(status=weibo_content)
# print "Press sina weibo successful, content is: %s" % status.text
iNum = 2
while True:
#上传图片,名称和内容如果重复,open api会检查,内容采用了取当前时间的机制
#图片名称从0-5循环遍历
status = api.upload( str(iNum)+'.jpg', 'test '+str(iNum) )
if iNum == MAX_PIC_NUM:
break
else:
iNum += 1
示例6: API
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
#如果不传送图片.
if ( ImagePath == None ):
#发布普通微博.
try:
#message为微博消息,lat为纬度,long为经度.
api.update_status( message, lat, long );
except WeibopError, e:
return e.reason;
#如果传送图片.
else:
#发布图文微博.
try:
#ImagePath为图片在操作系统中的访问地址,其余同上.
api.upload( ImagePath, message, lat, long );
except WeibopError, e:
return e.reason;
# 五、获取微博消息列表
#设定用户令牌密钥.
auth.setToken( atKey, atSecret );
#绑定用户验证信息.
api = API(auth);
WeiboList = [];
#获取微博列表.
#count为每页消息数量,page为从1开始计数的页码.
try:
timeline = api.user_timeline( count = count,
page = page );
except:
示例7: __init__
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import upload [as 别名]
class MyWeibo:
def __init__(self,app_key="3146673438",app_secret="f65a02335629c4ff5c4a5314fedfa97f"):
app_key=app_key
app_secret=app_secret
file=open("token","r")
token_key=file.readline()
token_secret=file.readline()
file.close()
auth=OAuthHandler(app_key,app_secret)
auth.setToken(token_key[0:-1],token_secret)
self.api=API(auth)
self.tts=pyTTS.sapi.SynthAndOutput()
self.mp=Dispatch("WMPlayer.OCX")##
self.count=30
self.chanel="好友频道"
self.name_list=[]
self.txt_list=[]
self.version="1.0"
self.firstplay=True
'''
tune=self.mp.newMedia("1.wav")
self.mp.currentPlaylist.appendItem(tune)
tune=self.mp.newMedia("2.mp3")
self.mp.currentPlaylist.appendItem(tune)
tune=self.mp.newMedia("3.mp3")
self.mp.currentPlaylist.appendItem(tune)
'''
def __del__(self):
self.deleteFiles()
def mute(self,flag):
self.mp.settings.mute=flag
def play(self):##
if self.firstplay:
self.firstplay=False
self.listen_to(self.chanel,n=self.count)
return True
if self.mp.controls.isAvailable("play")==False:
return False
self.mp.controls.play()
return True
def prev(self):
if self.mp.controls.isAvailable("previous")==False:
return False
self.mp.controls.previous()
return True
def next(self):
if self.mp.controls.isAvailable("next")==False:
return False
self.mp.controls.next()
return True
def pause(self):
if self.mp.controls.isAvailable("pause")==False:
return False
self.mp.controls.pause()
return True
def stop(self):
if self.mp.controls.isAvailable("stop")==False:
return False
self.mp.controls.stop()
return True
def faweibo(self,message):
message = message.encode("utf-8")
try:
self.api.update_status(status=message)
except:
return False
else:
return True
'''
def update_profile_image (self, filename):#上传图片
filename=filename.encode("utf-8")
self.api.update_profile_image(code(filename))'''
def upload(self, filename, message):#上传
message = message.encode("utf-8")
try:
self.api.upload(filename, status=message)
except Exception, e:
print e
return False
else: