2013-02-04 02:02:33 +00:00
|
|
|
from mega import Mega
|
|
|
|
|
2013-02-09 18:29:58 +00:00
|
|
|
|
2013-02-04 02:02:33 +00:00
|
|
|
def test():
|
|
|
|
#user details
|
2013-02-08 12:23:28 +00:00
|
|
|
email = 'your@email.com'
|
|
|
|
password = 'password'
|
2013-02-04 02:02:33 +00:00
|
|
|
|
|
|
|
mega = Mega()
|
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
##login
|
2013-02-09 18:29:58 +00:00
|
|
|
m = mega.login(email, password)
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
##get user details
|
2013-02-04 04:42:28 +00:00
|
|
|
details = m.get_user()
|
|
|
|
print(details)
|
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
##get account files
|
2013-02-04 02:02:33 +00:00
|
|
|
files = m.get_files()
|
2013-02-06 15:55:29 +00:00
|
|
|
#example iterate over files
|
|
|
|
for file in files:
|
|
|
|
if files[file]['a'] != False:
|
|
|
|
print files[file]
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
##upload file
|
2013-02-04 03:06:54 +00:00
|
|
|
print(m.upload('test.py'))
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-02-07 23:30:37 +00:00
|
|
|
##get file's public link
|
2013-02-08 12:21:32 +00:00
|
|
|
#NOTE: if passing upload() function response use get_upload_link()
|
|
|
|
file = m.find('test.py')
|
|
|
|
#print(m.get_upload_link(file))
|
|
|
|
print(m.get_link(file))
|
2013-02-07 23:30:37 +00:00
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
##trash a file, by id or url
|
2013-02-05 07:45:03 +00:00
|
|
|
#print(m.delete('f14U0JhD'))
|
|
|
|
#print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A'))
|
2013-02-04 21:15:18 +00:00
|
|
|
|
2013-02-07 19:44:57 +00:00
|
|
|
##search for a file in account
|
2013-02-08 12:21:32 +00:00
|
|
|
file = m.find('somefile.doc')
|
2013-02-07 19:44:57 +00:00
|
|
|
if file:
|
2013-02-07 18:06:03 +00:00
|
|
|
#trash a file by it's id
|
2013-02-07 19:44:57 +00:00
|
|
|
print(m.delete(file[1]['k']))
|
2013-02-07 18:06:03 +00:00
|
|
|
|
2013-02-11 12:47:22 +00:00
|
|
|
##download file
|
|
|
|
#file = m.find('test.py')
|
|
|
|
#m.download(file)
|
|
|
|
##specify destination folder
|
|
|
|
#m.download(file, '/home/user_name/Desktop')
|
2013-02-09 18:29:58 +00:00
|
|
|
#m.download_url('https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
|
|
|
|
|
2013-02-07 18:06:03 +00:00
|
|
|
|
2013-02-04 02:02:33 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
test()
|