def __init__(self, app_type="kuaipan"): sess = KuaipanSession(self._consumer_key, self._consumer_secret, app_type) self.api = KuaipanAPI(sess) if os.path.exists('.token'): fp = open('.token', 'rb') key = fp.readline() secret = fp.readline() fp.close() sess.token = oauth.oauth.OAuthToken(key[:-1], secret[:-1]) ret = self.account_info() if ret != False: print(u"%s 登陆成功..\n" % ret['user_name']) print(u"\t用户总空间:%dM" % (ret['quota_total'] / 1024 / 1024)) print(u"\t已使用空间:%dM" % (ret['quota_used'] / 1024 / 1024)) print(u"\t允许上传最大文件:%dM" % (ret['max_file_size'] / 1024 / 1024)) print("--------------------------------------\n") return url = self.api.requestToken() print(u"如果没有自动访问的话,请将下面链接复制到浏览器中。\n%s" % url) webbrowser.open(url) print(u"使用上面链接登陆成功后按回车键继续..") raw_input() self.api.accessToken() fp = open('.token', 'wb') fp.write(sess.token.key + '\n') fp.write(sess.token.secret + '\n') fp.close()
def __init__(self): sess = KuaipanSession(self._consumer_key, self._consumer_secret, "app_folder") self.api = KuaipanAPI(sess) url = self.api.requestToken() print url webbrowser.open(url) raw_input() #time.sleep(30) # sleep 授权 self.api.accessToken()
def __init__(self, app_type="kuaipan"): sess = KuaipanSession(self._consumer_key, self._consumer_secret, app_type) self.api = KuaipanAPI(sess) if os.path.exists('.token'): fp = open('.token', 'rb') key = fp.readline() secret = fp.readline() fp.close() sess.token = oauth.oauth.OAuthToken(key[:-1], secret[:-1]) ret = self.account_info() if ret != False: print(u"%s 登陆成功..\n" % ret['user_name']) print(u"\t用户总空间:%dM" % (ret['quota_total']/1024/1024)) print(u"\t已使用空间:%dM" % (ret['quota_used']/1024/1024)) print(u"\t允许上传最大文件:%dM" % (ret['max_file_size']/1024/1024)) print("--------------------------------------\n") return url = self.api.requestToken() print(u"如果没有自动访问的话,请将下面链接复制到浏览器中。\n%s" % url) webbrowser.open(url) print(u"使用上面链接登陆成功后按回车键继续..") raw_input() self.api.accessToken() fp = open('.token', 'wb') fp.write(sess.token.key + '\n') fp.write(sess.token.secret + '\n') fp.close()
class Demo(): _consumer_key = "xcAjfAIqjOde1UAe" _consumer_secret = "o7M7tKvsciqpwG36" def __init__(self): sess = KuaipanSession(self._consumer_key, self._consumer_secret, "app_folder") self.api = KuaipanAPI(sess) url = self.api.requestToken() print url webbrowser.open(url) raw_input() #time.sleep(30) # sleep 授权 self.api.accessToken() def test_acc_info(self): print "================acc_info====================" ret = self.api.account_info() print ret print ret['user_name'] def test_metadata(self): print "================meta_data===================" self.api.create_folder(u"/metadata文件") self.api.upload_file("/metadata文件/1.txt", "hello", True) self.api.upload_file("/metadata文件/2.txt", "world", True) ret = self.api.metadata(u"/metadata文件") assert ret['files'].__len__() == 2 ret = self.api.metadata(u"/metadata文件/1.txt") assert ret['name'] == u"1.txt" def test_shares(self): print "================shares======================" ret = self.api.create_folder(u"/文件share/") assert ret['msg'] == 'ok' ret = self.api.upload_file(u"/文件share/1.txt", "hello world!", True) self.api.shares(u"/文件share/1.txt") try: print self.api.shares(u"/文件share") except Exception, e: assert e.code == 404 else:
def setUp(self): sess = KuaipanSession("", "", "app_folder") sess.set_access_token("", "") self.api = KuaipanAPI(sess)
class TestKupanAPI(unittest.TestCase): def setUp(self): sess = KuaipanSession("", "", "app_folder") sess.set_access_token("", "") self.api = KuaipanAPI(sess) def test_acc_info(self): print "================acc_info====================" ret = self.api.account_info() assert int(ret['user_id']) == 3261479 def test_metadata(self): print "================meta_data===================" self.api.create_folder(u"/metadata文件") self.api.upload_file("/metadata文件/1.txt", "hello", True) self.api.upload_file("/metadata文件/2.txt", "world", True) ret = self.api.metadata(u"/metadata文件") assert ret['files'].__len__() == 2 ret = self.api.metadata(u"/metadata文件/1.txt") assert ret['name'] == u"1.txt" def test_shares(self): print "================shares======================" ret = self.api.create_folder(u"/文件share/") assert ret['msg'] == 'ok' ret = self.api.upload_file(u"/文件share/1.txt", "hello world!", True) self.api.shares(u"/文件share/1.txt") try: print self.api.shares(u"/文件share") except Exception, e: assert e.code == 404 else: