From 28208f1ba68c13d16a40fc55b2359e8bdbd41f62 Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Fri, 29 Dec 2017 02:56:15 +0100 Subject: [PATCH] format DL size in a human-readible way --- indexer.py | 10 ++++++++-- requirements.txt | 2 ++ templates/result.html | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/indexer.py b/indexer.py index 5a02339..dd5d921 100644 --- a/indexer.py +++ b/indexer.py @@ -6,6 +6,7 @@ import bencoder import requests from flask import Flask, render_template, url_for, request, send_file, redirect from werkzeug import secure_filename +from hurry.filesize import size app = Flask(__name__) strings = None settings = None @@ -71,8 +72,13 @@ def search(): search += " AND ".join(["torrents.fileid LIKE (?)"] * len(query.split(" "))) print(search) - c.execute("SELECT torrents.fileid, torrents.name, metadata.torrentsize FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE " + search, search_params) - results = c.fetchall() + #c.execute("SELECT torrents.fileid, torrents.name, metadata.torrentsize FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE " + search, search_params) + #results = c.fetchall() + results = list() + for row in c.execute("SELECT torrents.fileid, torrents.name, metadata.torrentsize FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE " + search, search_params): + r = row[0:2] + (size(float(row[2])) , ) + row[3:] + results.append(r) + return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"]) def scrapeAll(): diff --git a/requirements.txt b/requirements.txt index c7688c7..065179c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ bencoder==0.2.0 requests==2.18.2 +hurry.filesize==0.9 + diff --git a/templates/result.html b/templates/result.html index a70fd06..4d8b4bc 100644 --- a/templates/result.html +++ b/templates/result.html @@ -18,7 +18,7 @@ vim: ts=2 noexpandtab {% for result in results %} {{ result[1] }} - {{ result[2]|int / 1000 / 1000 }} + {{ result[2] }} N/A N/A N/A