diff --git a/torrentSearch/utils.py b/torrentSearch/utils.py index 2e429f8..7d51093 100644 --- a/torrentSearch/utils.py +++ b/torrentSearch/utils.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-11-01 15:57:23 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-11-02 15:14:31 +# @Last Modified time: 2017-11-02 16:20:29 import re from datetime import datetime @@ -47,4 +47,14 @@ def return_re_match(string, re_statement): def pagesToCount(multiple, total): if (multiple > total): return total - return multiple \ No newline at end of file + return multiple + + +def humansize(nbytes): + suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] + i = 0 + while nbytes >= 1024 and i < len(suffixes)-1: + nbytes /= 1024. + i += 1 + f = ('%.2f' % nbytes).rstrip('0').rstrip('.') + return '{} {}'.format(f, suffixes[i]) \ No newline at end of file