本文整理汇总了Python中mega.Mega类的典型用法代码示例。如果您正苦于以下问题:Python Mega类的具体用法?Python Mega怎么用?Python Mega使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mega类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test():
# user details
email = "[email protected]"
password = "password"
mega = Mega()
# login
m = mega.login(email, password)
# get user details
details = m.get_user()
print(details)
# get account files
files = m.get_files()
print(files)
# upload file
print(m.upload("test.py"))
# trash a file, by id or url
# print(m.delete('f14U0JhD'))
# print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A'))
# download file, by id+key or url
# m.download('6hBW0R4a','By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
m.download_url("https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00")
示例2: __init__
def __init__(self, *args, **kwargs):
usuario, senha = settings.MEGA['email'], settings.MEGA['password']
mega = Mega({'verbose': True})
self.m = mega.login(usuario, senha)
super(Command, self).__init__(*args, **kwargs)
示例3: test
def test():
#user details
email = '[email protected]'
password = 'password'
mega = Mega()
#login
m = mega.login(email, password)
#get user details
details = m.get_user()
print(details)
#get account files
files = m.get_files()
#example iterate over files
for file in files:
if files[file]['a'] != False:
print files[file]
#upload file
print(m.upload('test.py'))
#trash a file, by id or url
#print(m.delete('f14U0JhD'))
#print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A'))
#download file, by id+key or url
#m.download('6hBW0R4a','By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
m.download_url('https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
示例4: test
def test():
"""
Enter your account details to begin
comment/uncomment lines to test various parts of the API
see readme.md for more information
"""
#user details
email = '[email protected]'
password = 'password'
mega = Mega()
#mega = Mega({'verbose': True}) # verbose option for print output
# login
m = mega.login(email, password)
# get user details
details = m.get_user()
print(details)
# get account files
files = m.get_files()
# get account disk quota in MB
print(m.get_quota())
# get account storage space
print(m.get_storage_space())
# example iterate over files
for file in files:
print(files[file])
# upload file
print(m.upload('examples.py'))
# search for a file in account
file = m.find('examples.py')
if file:
# get public link
link = m.get_link(file)
print(link)
# download file. by file object or url
print m.download(file, '/tmp')
#m.download_url(link)
#delete or destroy file. by id or url
print(m.delete(file[0]))
#print(m.destroy(file[0]))
#print(m.delete_url(link))
#print(m.destroy_url(link))
# empty trash
print(m.empty_trash())
示例5: do_get
def do_get(self,filel):
mega = Mega()
m = mega.login('[email protected]','raghavan')
self.file=filel
try:
file1=m.find(self.file)
m.download(file1)
except:
file1=m.find(self.file)
m.download(file1)
示例6: do_put
def do_put(self,filel):
mega = Mega()
m = mega.login('[email protected]','raghavan')
self.filel=filel
for i in self.filel:
try:
file1 = m.upload(i)
except:
file1 = m.upload(i)
os.remove(i)
示例7: main
def main():
#display search menu
result = SearchInput()
#show found series
choice = DisplayResult(result)
#get title and episode objects
title = result[choice].name
episodes = GetEpisodes(result[choice].url)
numEpisodes = len(episodes)
#create directory for saving anime
w = Tkinter.Tk()
w.withdraw()
path = tkFileDialog.askdirectory()
if not os.path.exists(path):
print '[!] Error, quitting!'
return
#Bugfix for naming folders on windows
folderName = title.translate(None, '"<>:/\\|?*')
#Creating the folder
savePath = os.path.join(path, folderName)
if not os.path.exists(savePath):
os.mkdir(savePath)
#create Mega downloader object
mega = Mega({'verbose': True})
#Starting download...
Clear()
print version
print '[*] Downloading ' + title + ' in ' + savePath
print '[*] ' + str(numEpisodes) + ' episodes waiting for download...'
#iterate through episodes list and download
count = 0
for episode in episodes:
print '[*] Episode number ' + str(episode.num) + ' downloading...'
try:
mega.download_url(episode.url, savePath)
print '[*] Episode ' + str(episode.num) + ' downloaded!'
count = count + 1
except:
print '[!] Error! Could not download! Skipping!'
#Finish and exit if no errors
print '[*] ' + str(count) + ' chapters downloaded successfully!'
raw_input()
return
示例8: main
def main():
#display search menu
result = SearchInput()
#show found series
choice = DisplayResult(result)
#get title and episode objects
title = GetTitle(result[choice].url)
episodes = GetEpisodes(result[choice].url)
numEpisodes = len(episodes)
#create directory for saving anime
w = Tkinter.Tk()
w.withdraw()
path = tkFileDialog.askdirectory()
if not os.path.exists(path):
print '[!] Error, quitting!'
sys.exit(1)
#Bugfix for naming folders on windows
folderName = title.translate(None, '"<>:/\\|?*')
#Creating the folder
savePath = os.path.join(path, folderName)
if not os.path.exists(savePath):
os.mkdir(savePath)
#create Mega downloader object
mega = Mega({'verbose': True})
#Starting download...
Clear()
print version
print '[*] Descargando ' + title + ' en ' + savePath
print '[*] ' + str(numEpisodes) + ' capitulos en cola...'
#iterate through episodes list and download
for episode in episodes:
print '[*] Capitulo numero ' + str(episode.num) + ' descargando...'
try:
mega.download_url(episode.url, savePath)
except:
print '[!] Error! Saliendo!'
exit(1)
print '[*] Capitulo ' + str(episode.num) + ' descargado!'
return
#Finish and exit if no errors
print '[*] Descarga terminada! Presiona enter para salir.'
raw_input()
sys.exit(0)
示例9: mega_login
def mega_login(user=None, passwd=None):
""" Login to mega.co.nz
"""
global MEGA_OBJ
try:
mega = Mega({'verbose': True})
MEGA_OBJ = mega.login(user, passwd)
except Exception as error: #TODO: Find actual exception
LOGGER.error('Failed to login to mega.co.nz '
'check username or password.\n' + str(error))
sys.exit(1)
示例10: MegaBackend
class MegaBackend(duplicity.backend.Backend):
"""Connect to remote store using Mega.co.nz API"""
def __init__(self, parsed_url):
duplicity.backend.Backend.__init__(self, parsed_url)
try:
from mega import Mega
except ImportError:
raise BackendException('Mega.co.nz backend requires Mega.co.nz APIs Python Module'
'(see https://github.com/richardasaurus/mega.py).')
# Setup client instance.
self.client = Mega()
self.client.domain = parsed_url.hostname
self.__authorize(parsed_url.username, self.get_password())
# Fetch destination folder entry (and crete hierarchy if required).
folder_names = parsed_url.path[1:].split('/')
files = self.client.get_files()
parent_folder = self.client.root_id
for folder_name in folder_names:
entries = self.__filter_entries(files, parent_folder, folder_name, 'folder')
if len(entries):
# use first matching folder as new parent
parent_folder = entries.keys()[0]
else:
# create subfolder if folder doesn't exist and use its handle as parent
folder_node = self.client.create_folder(folder_name, parent_folder)
parent_folder = self.client.get_id_from_obj(folder_node)
# update filelist after creating new folder
files = self.client.get_files()
self.folder = parent_folder
@retry
def put(self, source_path, remote_filename=None, raise_errors=False):
"""Transfer source_path to remote_filename"""
# Default remote file name.
if not remote_filename:
remote_filename = source_path.get_filename()
try:
# If remote file already exists in destination folder, remove it.
files = self.client.get_files()
entries = self.__filter_entries(files, self.folder, remote_filename, 'file')
for entry in entries:
self.client.delete(entry)
self.client.upload(source_path.get_canonical(), self.folder, dest_filename=remote_filename)
except Exception, e:
self.__handle_error("Failed to upload file '%s' to remote folder '%s': %s"
% (source_path.get_canonical(), self.__get_node_name(self.folder), str(e)), raise_errors)
示例11: mega_upload_files
def mega_upload_files(root, files, dest=None):
mega = Mega()
m = mega.login(config.get_username(), config.get_password())
for filename in files:
current = os.path.join(root, filename)
print("Uploading: " + str(current))
uploaded = m.upload(current)
print(m.get_upload_link(uploaded))
if dest != None:
fileRef = m.find(filename)
folder = m.find(dest)
m.move(fileRef[0], folder)
示例12: test
def test():
#user details
email = '[email protected]'
password = 'password'
mega = Mega()
#login
m = mega.login(email, password)
#get user details
details = m.get_user()
print(details)
#get account files
files = m.get_files()
#get account disk quota in MB
print(m.get_quota())
#example iterate over files
for file in files:
print(files[file])
#upload file
print(m.upload('tests.py'))
#search for a file in account
file = m.find('tests.py')
if file:
#get public link
link = m.get_link(file)
print(link)
#download file. by file object or url
m.download(file, '/tmp')
#m.download_url(link)
#delete or destroy file. by id or url
print(m.delete(file[0]))
#print(m.destroy(file[0]))
#print(m.delete_url(link))
#print(m.destroy_url(link))
#empty trash
print(m.empty_trash())
示例13: get_api
def get_api(self) :
if (self._api is None) :
if (self._sid != '') :
self._api = Mega()
self._api.sid = self._sid
self._api.master_key = self._master_key
self._api.sequence_num = self._sequence_num
self._api.users_keys = {}
elif self._login is not None and self._password is not None :
self._api = Mega()
try :
self._api.login(self._login, self._password)
except Exception :
self.errorexit(_('login failled'))
return self._api
示例14: login
def login(self,args,kwargs) :
"""login to mega"""
if 'email' in kwargs :
self._email = kwargs['email']
self.save_config()
elif len(args) > 0 :
self._email = args[0]
self.save_config()
if self._email is None :
self.errorexit(_('need email to login'))
sys.stdout.write('Login : [%s]\n' % (self._email,))
password = getpass.getpass()
if len(password) == 0 :
self.errorexit(_('need a password to login'))
self._api = Mega()
try :
self._api.login(self._email,password)
except Exception :
self.errorexit(_('login failled'))
self._sid = self._api.sid
self._master_key = self._api.master_key
self.save_config()
self.status('login success')
示例15: __init__
def __init__(self, parsed_url):
duplicity.backend.Backend.__init__(self, parsed_url)
try:
from mega import Mega
except ImportError:
raise BackendException('Mega.co.nz backend requires Mega.co.nz APIs Python Module'
'(see https://github.com/richardasaurus/mega.py).')
# Setup client instance.
self.client = Mega()
self.client.domain = parsed_url.hostname
self.__authorize(parsed_url.username, self.get_password())
# Fetch destination folder entry (and crete hierarchy if required).
folder_names = parsed_url.path[1:].split('/')
files = self.client.get_files()
parent_folder = self.client.root_id
for folder_name in folder_names:
entries = self.__filter_entries(files, parent_folder, folder_name, 'folder')
if len(entries):
# use first matching folder as new parent
parent_folder = entries.keys()[0]
else:
# create subfolder if folder doesn't exist and use its handle as parent
folder_node = self.client.create_folder(folder_name, parent_folder)
parent_folder = self.client.get_id_from_obj(folder_node)
# update filelist after creating new folder
files = self.client.get_files()
self.folder = parent_folder