2019-10-16 20:20:22 +00:00
|
|
|
import os
|
2013-02-04 02:02:33 +00:00
|
|
|
from mega import Mega
|
|
|
|
|
2013-04-19 18:38:45 +00:00
|
|
|
|
2013-02-04 02:02:33 +00:00
|
|
|
def test():
|
2013-04-23 18:58:18 +00:00
|
|
|
"""
|
|
|
|
Enter your account details to begin
|
|
|
|
comment/uncomment lines to test various parts of the API
|
|
|
|
see readme.md for more information
|
|
|
|
"""
|
|
|
|
|
2019-10-16 20:20:22 +00:00
|
|
|
# user details
|
|
|
|
email = os.environ['EMAIL']
|
|
|
|
password = os.environ['PASS']
|
2013-02-04 02:02:33 +00:00
|
|
|
|
|
|
|
mega = Mega()
|
2019-10-16 20:20:22 +00:00
|
|
|
# mega = Mega({'verbose': True}) # verbose option for print output
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-04-28 15:56:17 +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-04-28 15:56:17 +00:00
|
|
|
# get user details
|
2013-02-04 04:42:28 +00:00
|
|
|
details = m.get_user()
|
|
|
|
print(details)
|
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# get account files
|
2013-02-04 02:02:33 +00:00
|
|
|
files = m.get_files()
|
2013-02-23 15:06:02 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# get account disk quota in MB
|
2019-10-16 20:59:31 +00:00
|
|
|
print((m.get_quota()))
|
2013-04-28 15:56:17 +00:00
|
|
|
# get account storage space
|
2019-10-16 20:59:31 +00:00
|
|
|
print((m.get_storage_space()))
|
2013-03-10 03:38:22 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# example iterate over files
|
2013-02-06 15:55:29 +00:00
|
|
|
for file in files:
|
2019-10-16 20:59:31 +00:00
|
|
|
print((files[file]))
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# upload file
|
2019-10-16 20:59:31 +00:00
|
|
|
print((m.upload('examples.py')))
|
2013-02-04 02:02:33 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# search for a file in account
|
2013-05-15 23:44:32 +00:00
|
|
|
file = m.find('examples.py')
|
2013-02-04 21:15:18 +00:00
|
|
|
|
2013-02-07 19:44:57 +00:00
|
|
|
if file:
|
2013-04-28 15:56:17 +00:00
|
|
|
# get public link
|
2013-02-23 15:06:02 +00:00
|
|
|
link = m.get_link(file)
|
|
|
|
print(link)
|
2013-02-07 18:06:03 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# download file. by file object or url
|
2019-10-16 20:59:31 +00:00
|
|
|
print(m.download(file, '/tmp'))
|
2019-10-16 20:20:22 +00:00
|
|
|
# m.download_url(link)
|
2013-02-23 15:06:02 +00:00
|
|
|
|
2019-10-16 20:20:22 +00:00
|
|
|
# delete or destroy file. by id or url
|
2019-10-16 20:59:31 +00:00
|
|
|
print((m.delete(file[0])))
|
2019-10-16 20:20:22 +00:00
|
|
|
# print(m.destroy(file[0]))
|
|
|
|
# print(m.delete_url(link))
|
|
|
|
# print(m.destroy_url(link))
|
2013-02-09 18:29:58 +00:00
|
|
|
|
2013-04-28 15:56:17 +00:00
|
|
|
# empty trash
|
2019-10-16 20:59:31 +00:00
|
|
|
print((m.empty_trash()))
|
2013-02-07 18:06:03 +00:00
|
|
|
|
2019-10-16 20:20:22 +00:00
|
|
|
|
2013-02-04 02:02:33 +00:00
|
|
|
if __name__ == '__main__':
|
2019-10-16 20:20:22 +00:00
|
|
|
test()
|