Exports are downloadable

This commit is contained in:
Simon 2018-06-06 11:12:24 -04:00
parent 0b1d76f478
commit 7ac7972fd6
8 changed files with 71 additions and 10 deletions

20
app.py
View File

@ -1,6 +1,7 @@
from flask import Flask, render_template, redirect, request, flash, abort, Response
import os
import json
import time
from database import Database, Website, InvalidQueryException
from flask_recaptcha import ReCaptcha
import od_util
@ -23,6 +24,23 @@ app.jinja_env.globals.update(get_mime=od_util.get_mime)
tm = TaskManager()
@app.template_filter("datetime_format")
def datetime_format(value, format='%Y-%m-%d %H:%M UTC'):
return time.strftime(format, time.gmtime(value))
@app.route("/dl")
def downloads():
try:
export_file_stats = os.stat("static/out.csv.xz")
except FileNotFoundError:
print("No export file")
export_file_stats = None
return render_template("downloads.html", export_file_stats=export_file_stats)
@app.route("/website/<int:website_id>/")
def website_info(website_id):
@ -109,7 +127,7 @@ def submit():
@app.route("/enqueue", methods=["POST"])
def enqueue():
if not recaptcha.verify():
if recaptcha.verify():
url = os.path.join(request.form.get("url"), "")

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
sqlite3 -header -csv db.sqlite3 < export.sql > out.csv
echo "Exported $(wc -l < out.csv) files"
rm out.csv.xz
xz out.csv
echo "Compressed to $(stat --printf="%s" out.csv.xz) bytes"
sqlite3 -header -csv db.sqlite3 < export.sql > static/out.csv
echo "Exported $(wc -l < static/out.csv) files"
rm static/out.csv.xz
xz static/out.csv
echo "Compressed to $(stat --printf="%s" static/out.csv.xz) bytes"

37
templates/downloads.html Normal file
View File

@ -0,0 +1,37 @@
{% extends "layout.html" %}
{% set title = "Downloads - OD-Database" %}
{% set current_page = "dl" %}
{% block body %}
<div class="container">
<div class="card">
<div class="card-header">Downloads</div>
<div class="card-body">
<p>The entire database is exported to CSV every ±30min</p>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Size</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% if export_file_stats %}
<tr>
<td>out.csv.xz</td>
<td>{{ export_file_stats.st_size }}</td>
<td>{{ export_file_stats.st_mtime|datetime_format }}</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock body %}

View File

@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% set current_page = "home" %}
{% set title = "OD-Database - Home" %}
{% block body %}

View File

@ -37,6 +37,9 @@
<li class="nav-item">
<a class="nav-link {{ "active" if current_page == "contribute" else "" }}" href="/contribute">Contribute</a>
</li>
<li class="nav-item">
<a class="nav-link {{ "active" if current_page == "dl" else "" }}" href="/dl">Downloads</a>
</li>
</ul>
</div>
</nav>

View File

@ -1,4 +1,5 @@
{% extends "layout.html" %}
{% set current_page = "search" %}
{% set title = "OD-Database - Search" %}

View File

@ -1,5 +1,6 @@
{% extends "layout.html" %}
{% set title = "OD-Database - Submit website" %}
{% set current_page = "submit" %}
{% block body %}
<div class="container" >
@ -12,7 +13,7 @@
</div>
<div class="row">
<div class="col">
{# {{ recaptcha.get_code()|safe }}#}
{{ recaptcha.get_code()|safe }}
</div>
<div class="col">
<input class="btn btn-primary" type="submit" value="Submit" title="Submit open directory">
@ -23,8 +24,8 @@
<hr>
<p class="text-muted">
Note: TODO note
<p class="text-muted">By submitting this form you agree that your IP address and User Agent will be
saved (for debugging purposes only).
</p>
</div>
</div>

View File

@ -1,5 +1,6 @@
{% extends "layout.html" %}
{% set title = "OD-Datase - Websites" %}
{% set current_page = "website" %}
{% block body %}
<div class="container">