read me update and tests
This commit is contained in:
parent
36bed09dde
commit
d15be6deff
3 changed files with 20 additions and 13 deletions
|
@ -43,6 +43,11 @@ balance = m.get_balance()
|
||||||
```python
|
```python
|
||||||
quota = m.get_quota()
|
quota = m.get_quota()
|
||||||
```
|
```
|
||||||
|
### Get account storage space
|
||||||
|
```python
|
||||||
|
# unit output kilo, mega, gig, otherwise bytes output
|
||||||
|
space = m.get_storage_space(kilo=True)
|
||||||
|
```
|
||||||
### Get account files
|
### Get account files
|
||||||
```python
|
```python
|
||||||
files = m.get_files()
|
files = m.get_files()
|
||||||
|
|
|
@ -305,11 +305,11 @@ class Mega(object):
|
||||||
raise ValueError("Only one unit prefix can be specified")
|
raise ValueError("Only one unit prefix can be specified")
|
||||||
unit_coef = 1
|
unit_coef = 1
|
||||||
if kilo:
|
if kilo:
|
||||||
unit_coef = 1024.
|
unit_coef = 1024
|
||||||
if mega:
|
if mega:
|
||||||
unit_coef = 1048576.
|
unit_coef = 1048576
|
||||||
if giga:
|
if giga:
|
||||||
unit_coef = 1073741824.
|
unit_coef = 1073741824
|
||||||
json_resp = self.api_request({'a': 'uq', 'xfer': 1, 'strg': 1})
|
json_resp = self.api_request({'a': 'uq', 'xfer': 1, 'strg': 1})
|
||||||
return {
|
return {
|
||||||
'used': json_resp['cstrg'] / unit_coef,
|
'used': json_resp['cstrg'] / unit_coef,
|
||||||
|
|
22
tests.py
22
tests.py
|
@ -15,35 +15,37 @@ def test():
|
||||||
mega = Mega()
|
mega = Mega()
|
||||||
#mega = Mega({'verbose': True}) # verbose option for print output
|
#mega = Mega({'verbose': True}) # verbose option for print output
|
||||||
|
|
||||||
#login
|
# login
|
||||||
m = mega.login(email, password)
|
m = mega.login(email, password)
|
||||||
|
|
||||||
#get user details
|
# get user details
|
||||||
details = m.get_user()
|
details = m.get_user()
|
||||||
print(details)
|
print(details)
|
||||||
|
|
||||||
#get account files
|
# get account files
|
||||||
files = m.get_files()
|
files = m.get_files()
|
||||||
|
|
||||||
#get account disk quota in MB
|
# get account disk quota in MB
|
||||||
print(m.get_quota())
|
print(m.get_quota())
|
||||||
|
# get account storage space
|
||||||
|
print(m.get_storage_space())
|
||||||
|
|
||||||
#example iterate over files
|
# example iterate over files
|
||||||
for file in files:
|
for file in files:
|
||||||
print(files[file])
|
print(files[file])
|
||||||
|
|
||||||
#upload file
|
# upload file
|
||||||
print(m.upload('tests.py'))
|
print(m.upload('tests.py'))
|
||||||
|
|
||||||
#search for a file in account
|
# search for a file in account
|
||||||
file = m.find('tests.py')
|
file = m.find('tests.py')
|
||||||
|
|
||||||
if file:
|
if file:
|
||||||
#get public link
|
# get public link
|
||||||
link = m.get_link(file)
|
link = m.get_link(file)
|
||||||
print(link)
|
print(link)
|
||||||
|
|
||||||
#download file. by file object or url
|
# download file. by file object or url
|
||||||
print m.download(file, '/tmp')
|
print m.download(file, '/tmp')
|
||||||
#m.download_url(link)
|
#m.download_url(link)
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ def test():
|
||||||
#print(m.delete_url(link))
|
#print(m.delete_url(link))
|
||||||
#print(m.destroy_url(link))
|
#print(m.destroy_url(link))
|
||||||
|
|
||||||
#empty trash
|
# empty trash
|
||||||
print(m.empty_trash())
|
print(m.empty_trash())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue