2007-09-02 11:58:25 +04:00
|
|
|
#VERSION: 1.11
|
|
|
|
|
2007-08-31 16:06:31 +04:00
|
|
|
def prettyPrinter(dictionnary):
|
|
|
|
dictionnary['size'] = anySizeToBytes(dictionnary['size'])
|
|
|
|
print "%(link)s|%(name)s|%(size)s|%(seeds)s|%(leech)s|%(engine_url)s" % dictionnary
|
|
|
|
|
|
|
|
def anySizeToBytes(size_string):
|
|
|
|
"""
|
|
|
|
Convert a string like '1 KB' to '1024' (bytes)
|
|
|
|
"""
|
|
|
|
# separate integer from unit
|
|
|
|
try:
|
|
|
|
size, unit = size_string.split()
|
2007-09-02 11:58:25 +04:00
|
|
|
except:
|
2007-08-31 16:06:31 +04:00
|
|
|
try:
|
|
|
|
size = size_string.strip()
|
|
|
|
unit = ''.join([c for c in size if c.isalpha()])
|
|
|
|
size = size[:-len(unit)]
|
2007-09-02 11:58:25 +04:00
|
|
|
except:
|
2007-08-31 16:06:31 +04:00
|
|
|
return -1
|
2007-09-02 11:58:25 +04:00
|
|
|
if len(size) == 0:
|
|
|
|
return -1
|
2007-08-31 16:06:31 +04:00
|
|
|
size = float(size)
|
|
|
|
short_unit = unit.upper()[0]
|
|
|
|
|
|
|
|
# convert
|
|
|
|
units_dict = { 'T': 40, 'G': 30, 'M': 20, 'K': 10 }
|
|
|
|
if units_dict.has_key( short_unit ):
|
|
|
|
size = size * 2**units_dict[short_unit]
|
|
|
|
return int(size)
|