qBittorrent
nova3.novaprinter Namespace Reference

Functions

def prettyPrinter (dictionary)
 
def anySizeToBytes (size_string)
 

Function Documentation

◆ anySizeToBytes()

def nova3.novaprinter.anySizeToBytes (   size_string)
Convert a string like '1 KB' to '1024' (bytes)

Definition at line 41 of file novaprinter.py.

41 def anySizeToBytes(size_string):
42  """
43  Convert a string like '1 KB' to '1024' (bytes)
44  """
45  # separate integer from unit
46  try:
47  size, unit = size_string.split()
48  except:
49  try:
50  size = size_string.strip()
51  unit = ''.join([c for c in size if c.isalpha()])
52  if len(unit) > 0:
53  size = size[:-len(unit)]
54  except:
55  return -1
56  if len(size) == 0:
57  return -1
58  size = float(size)
59  if len(unit) == 0:
60  return int(size)
61  short_unit = unit.upper()[0]
62 
63  # convert
64  units_dict = {'T': 40, 'G': 30, 'M': 20, 'K': 10}
65  if short_unit in units_dict:
66  size = size * 2**units_dict[short_unit]
67  return int(size)
QString join(const QList< QStringView > &strings, QStringView separator)
Definition: string.cpp:102
def anySizeToBytes(size_string)
Definition: novaprinter.py:41

References Utils::String.join().

Referenced by nova3.novaprinter.prettyPrinter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prettyPrinter()

def nova3.novaprinter.prettyPrinter (   dictionary)

Definition at line 28 of file novaprinter.py.

28 def prettyPrinter(dictionary):
29  dictionary['size'] = anySizeToBytes(dictionary['size'])
30  outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "),
31  str(dictionary["size"]), str(dictionary["seeds"]),
32  str(dictionary["leech"]), dictionary["engine_url"]))
33  if 'desc_link' in dictionary:
34  outtext = "|".join((outtext, dictionary["desc_link"]))
35 
36  # fd 1 is stdout
37  with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
38  print(outtext, file=utf8stdout)
39 
40 
def prettyPrinter(dictionary)
Definition: novaprinter.py:28

References nova3.novaprinter.anySizeToBytes(), and Utils::String.join().

Here is the call graph for this function: