changes to delete, destroy functions. see readme for updated usage. delete_url functions non-working currently

This commit is contained in:
richard@richard.do 2013-03-05 01:48:01 +00:00
parent 9bbb2b815b
commit d444be92b4
3 changed files with 15 additions and 19 deletions

View file

@ -52,17 +52,17 @@ This is a work in progress, further functionality coming shortly.
file = m.find('myfile.doc') file = m.find('myfile.doc')
m.get_link(file) m.get_link(file)
### Trash or destroy a file from URL, it's ID, or from search ### Trash or destroy a file from URL or its ID
m.delete('utYjgSTQ') m.delete(file[0])
m.delete_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc') m.delete_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
m.destroy('utYjgSTQ') m.destroy(file[0])
m.destroy_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc') m.destroy_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
files = m.find('myfile.doc') files = m.find('myfile.doc')
if files: if files:
m.delete(files[1]['k']) m.delete(files[0])
## Requirements ## Requirements

View file

@ -269,6 +269,7 @@ class Mega(object):
def get_id_from_public_handle(self, public_handle): def get_id_from_public_handle(self, public_handle):
#get node data #get node data
#TODO fix this function
node_data = self.api_request({'a': 'f', 'f': 1, 'p': public_handle}) node_data = self.api_request({'a': 'f', 'f': 1, 'p': public_handle})
node_id = None node_id = None
@ -288,7 +289,8 @@ class Mega(object):
#delete a file via it's url #delete a file via it's url
path = self.parse_url(url).split('!') path = self.parse_url(url).split('!')
public_handle = path[0] public_handle = path[0]
return self.move(public_handle, 4) file_id = self.get_id_from_public_handle(public_handle)
return self.move(file_id, 4)
def destroy(self, file_id): def destroy(self, file_id):
#delete forever by private id #delete forever by private id
@ -302,8 +304,7 @@ class Mega(object):
file_id = self.get_id_from_public_handle(public_handle) file_id = self.get_id_from_public_handle(public_handle)
return self.destroy(file_id) return self.destroy(file_id)
def move(self, public_handle, target): def move(self, file_id, target):
#TODO node_id improvements
''' '''
Move a file to another parent node Move a file to another parent node
params: params:
@ -317,17 +318,12 @@ class Mega(object):
3 : inbox 3 : inbox
4 : trash 4 : trash
''' '''
#get node data
node_data = self.api_request({'a': 'f', 'f': 1, 'p': public_handle}) #determine target_node_id
target_node_id = str(self.get_node_by_type(target)[0]) target_node_id = str(self.get_node_by_type(target)[0])
node_id = None return self.api_request({'a': 'm',
'n': file_id,
#determine node id 't': target_node_id,
for i in node_data['f']:
if i['h'] is not u'':
node_id = i['h']
return self.api_request({'a': 'm', 'n': node_id, 't': target_node_id,
'i': self.request_id}) 'i': self.request_id})

View file

@ -37,8 +37,8 @@ def test():
#m.download_url(link) #m.download_url(link)
#delete or destroy file. by id or url #delete or destroy file. by id or url
print(m.delete(file[1]['k'])) print(m.delete(file[0]))
#print(m.destroy(file[1]['h'])) #print(m.destroy(file[0]))
#print(m.delete_url(link)) #print(m.delete_url(link))
#print(m.destroy_url(link)) #print(m.destroy_url(link))