當前位置: 首頁>>代碼示例>>Python>>正文


Python mega.Mega類代碼示例

本文整理匯總了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")
開發者ID:bussiere,項目名稱:mega.py,代碼行數:28,代碼來源:test.py

示例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)
開發者ID:gustavosf,項目名稱:cdzforever.net,代碼行數:7,代碼來源:syncfiles.py

示例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')
開發者ID:si73,項目名稱:mega.py,代碼行數:31,代碼來源:test.py

示例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())
開發者ID:Ilgrim,項目名稱:mega.py,代碼行數:56,代碼來源:examples.py

示例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)
開發者ID:koshikraj,項目名稱:master-cloud,代碼行數:10,代碼來源:main.py

示例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)
開發者ID:koshikraj,項目名稱:master-cloud,代碼行數:10,代碼來源:main.py

示例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
開發者ID:shakku,項目名稱:animeDown,代碼行數:55,代碼來源:animeDown.py

示例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)
開發者ID:tamuraa,項目名稱:animeDown,代碼行數:55,代碼來源:animeDown.py

示例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)
開發者ID:peterfisher,項目名稱:mega-sync,代碼行數:13,代碼來源:mega_sync.py

示例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)
開發者ID:hurlebouc,項目名稱:GDuplicity,代碼行數:56,代碼來源:megabackend.py

示例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)
開發者ID:jorgarga,項目名稱:megauploader,代碼行數:14,代碼來源:megauploader.py

示例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())
開發者ID:SigmoidFreud,項目名稱:mega.py,代碼行數:48,代碼來源:tests.py

示例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
開發者ID:ToX82,項目名稱:megacl,代碼行數:16,代碼來源:commandline.py

示例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')
開發者ID:ToX82,項目名稱:megacl,代碼行數:25,代碼來源:commandline.py

示例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
開發者ID:hurlebouc,項目名稱:GDuplicity,代碼行數:32,代碼來源:megabackend.py


注:本文中的mega.Mega類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。