From 7ac7972fd61818207c7281cb4178587a6e8b1a61 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 6 Jun 2018 11:12:24 -0400 Subject: [PATCH] Exports are downloadable --- app.py | 20 +++++++++++++++++++- export.sh | 10 +++++----- templates/downloads.html | 37 +++++++++++++++++++++++++++++++++++++ templates/home.html | 2 +- templates/layout.html | 3 +++ templates/search.html | 1 + templates/submit.html | 7 ++++--- templates/website.html | 1 + 8 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 templates/downloads.html diff --git a/app.py b/app.py index 1d88833..5c16cff 100644 --- a/app.py +++ b/app.py @@ -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//") 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"), "") diff --git a/export.sh b/export.sh index f2a1af6..8379aa8 100755 --- a/export.sh +++ b/export.sh @@ -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" \ No newline at end of file +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" \ No newline at end of file diff --git a/templates/downloads.html b/templates/downloads.html new file mode 100644 index 0000000..397e6e6 --- /dev/null +++ b/templates/downloads.html @@ -0,0 +1,37 @@ +{% extends "layout.html" %} +{% set title = "Downloads - OD-Database" %} +{% set current_page = "dl" %} + +{% block body %} +
+
+
Downloads
+
+ +

The entire database is exported to CSV every ±30min

+ + + + + + + + + + + + + {% if export_file_stats %} + + + + + + {% endif %} + + +
DescriptionSizeDate
out.csv.xz{{ export_file_stats.st_size }}{{ export_file_stats.st_mtime|datetime_format }}
+
+
+
+{% endblock body %} diff --git a/templates/home.html b/templates/home.html index b9407b2..e921b7b 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} - +{% set current_page = "home" %} {% set title = "OD-Database - Home" %} {% block body %} diff --git a/templates/layout.html b/templates/layout.html index 9df955b..435a8a7 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -37,6 +37,9 @@ + diff --git a/templates/search.html b/templates/search.html index c1d73ff..ddd28b2 100644 --- a/templates/search.html +++ b/templates/search.html @@ -1,4 +1,5 @@ {% extends "layout.html" %} +{% set current_page = "search" %} {% set title = "OD-Database - Search" %} diff --git a/templates/submit.html b/templates/submit.html index 08e642b..2b5db20 100644 --- a/templates/submit.html +++ b/templates/submit.html @@ -1,5 +1,6 @@ {% extends "layout.html" %} {% set title = "OD-Database - Submit website" %} +{% set current_page = "submit" %} {% block body %}
@@ -12,7 +13,7 @@
-{# {{ recaptcha.get_code()|safe }}#} + {{ recaptcha.get_code()|safe }}
@@ -23,8 +24,8 @@
-

- Note: TODO note +

By submitting this form you agree that your IP address and User Agent will be + saved (for debugging purposes only).

diff --git a/templates/website.html b/templates/website.html index fbcb8ab..15eaefd 100644 --- a/templates/website.html +++ b/templates/website.html @@ -1,5 +1,6 @@ {% extends "layout.html" %} {% set title = "OD-Datase - Websites" %} +{% set current_page = "website" %} {% block body %}