From dcbd17a6ed8df26b5f7f13ac45c2ebbd68a4f08d Mon Sep 17 00:00:00 2001 From: gissehel Date: Sat, 20 Apr 2013 13:45:06 +0200 Subject: [PATCH 1/2] Explicitly declaring dependency in setup.py make 'pip install mega.py' install everything just fine --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6d7b98b..d4aa889 100644 --- a/setup.py +++ b/setup.py @@ -38,10 +38,11 @@ setup( author_email='richard@richard.do', license='Creative Commons Attribution-Noncommercial-Share Alike license', long_description='https://github.com/richardasaurus/mega.py', + install_requires=['pycrypto', 'requests'], classifiers=[ 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Internet :: WWW/HTTP' ] -) \ No newline at end of file +) From 58d89c23b6d9bc0dde0dc38cae33e7cb5a6fdf8f Mon Sep 17 00:00:00 2001 From: gissehel Date: Sun, 21 Apr 2013 18:53:48 +0200 Subject: [PATCH 2/2] get_storage_space retrieve the used space and total space currently associated with the account --- mega/mega.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mega/mega.py b/mega/mega.py index ce369d9..8c2667c 100644 --- a/mega/mega.py +++ b/mega/mega.py @@ -289,6 +289,29 @@ class Mega(object): #convert bytes to megabyes return json_resp['mstrg'] / 1048576 + def get_storage_space(self, giga=False, mega=False, kilo=False): + """ + Get the current storage space. + Return a dict containing at least: + 'used' : the used space on the account + 'total' : the maximum space allowed with current plan + All storage space are in bytes unless asked differently. + """ + if sum(1 if x else 0 for x in (kilo, mega, giga)) > 1: + raise ValueError("Only one unit prefix can be specified") + unit_coef = 1 + if kilo: + unit_coef = 1024. + if mega: + unit_coef = 1048576. + if giga: + unit_coef = 1073741824. + json_resp = self.api_request({'a': 'uq', 'xfer': 1, 'strg': 1}) + return { + 'used': json_resp['cstrg'] / unit_coef, + 'total': json_resp['mstrg'] / unit_coef, + } + def get_balance(self): """ Get account monetary balance, Pro accounts only