format DL size in a human-readible way

This commit is contained in:
Stefan Rupp 2017-12-29 02:56:15 +01:00
parent a67182df2c
commit 28208f1ba6
3 changed files with 11 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import bencoder
import requests import requests
from flask import Flask, render_template, url_for, request, send_file, redirect from flask import Flask, render_template, url_for, request, send_file, redirect
from werkzeug import secure_filename from werkzeug import secure_filename
from hurry.filesize import size
app = Flask(__name__) app = Flask(__name__)
strings = None strings = None
settings = None settings = None
@ -71,8 +72,13 @@ def search():
search += " AND ".join(["torrents.fileid LIKE (?)"] * len(query.split(" "))) search += " AND ".join(["torrents.fileid LIKE (?)"] * len(query.split(" ")))
print(search) 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) #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 = 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"]) return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"])
def scrapeAll(): def scrapeAll():

View file

@ -1,2 +1,4 @@
bencoder==0.2.0 bencoder==0.2.0
requests==2.18.2 requests==2.18.2
hurry.filesize==0.9

View file

@ -18,7 +18,7 @@ vim: ts=2 noexpandtab
{% for result in results %} {% for result in results %}
<tr> <tr>
<td><a href="/download/{{ result[0] }}">{{ result[1] }}</a></td> <td><a href="/download/{{ result[0] }}">{{ result[1] }}</a></td>
<td>{{ result[2]|int / 1000 / 1000 }}</td> <td>{{ result[2] }}</td>
<td>N/A</td> <td>N/A</td>
<td>N/A</td> <td>N/A</td>
<td>N/A</td> <td>N/A</td>