def convert_db_torrent_to_json(torrent, include_rel_score=False):
 torrent_name = torrent[2]
 if ((torrent_name is None) or (len(torrent_name.strip()) == 0)):
  torrent_name = 'Unnamed torrent'
 res_json = {'id': torrent[0], 'infohash': torrent[1].encode('hex'), 'name': torrent_name, 'size': torrent[3], 'category': torrent[4], 'num_seeders': (torrent[5] or 0), 'num_leechers': (torrent[6] or 0), 'last_tracker_check': (torrent[7] or 0)}
 if include_rel_score:
  res_json['relevance_score'] = torrent[9]
 return res_json

def convert_db_torrent_to_json ( torrent , include_rel_score = False ) : torrent_name = torrent [ 2 ] if ( ( torrent_name is None ) or ( len ( torrent_name . strip ( ) ) == 0 ) ) : torrent_name = 'Unnamed torrent' res_json = { 'id' : torrent [ 0 ] , 'infohash' : torrent [ 1 ] . encode ( 'hex' ) , 'name' : torrent_name , 'size' : torrent [ 3 ] , 'category' : torrent [ 4 ] , 'num_seeders' : ( torrent [ 5 ] or 0 ) , 'num_leechers' : ( torrent [ 6 ] or 0 ) , 'last_tracker_check' : ( torrent [ 7 ] or 0 ) } if include_rel_score : res_json [ 'relevance_score' ] = torrent [ 9 ] return res_json
this method converts a torrent in the database to a json dictionary .