mirror of
https://github.com/simon987/od-database.git
synced 2025-04-10 14:06:45 +00:00
commit
38dfb657ed
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
||||
.idea/
|
||||
.idea/
|
||||
/static/downloads/
|
||||
!/static/downloads/README.md
|
29
app.py
29
app.py
@ -82,13 +82,30 @@ def from_timestamp(value):
|
||||
@app.route("/dl")
|
||||
@cache.cached(120)
|
||||
def downloads():
|
||||
try:
|
||||
export_file_stats = os.stat("static/out.csv.lzm4")
|
||||
except FileNotFoundError:
|
||||
logger.warning("No export file to display in /dl")
|
||||
export_file_stats = None
|
||||
# Get content of downloads directory
|
||||
dl_dir = "static/downloads/"
|
||||
dir_content = os.listdir(dl_dir)
|
||||
|
||||
return render_template("downloads.html", export_file_stats=export_file_stats)
|
||||
# Make paths relative to working directory
|
||||
# Only allow csv files
|
||||
files = [
|
||||
(name, os.path.join(dl_dir, name))
|
||||
for name in dir_content
|
||||
if name.find(".csv") != -1
|
||||
]
|
||||
|
||||
# Stat files
|
||||
# Remove any dirs placed accidentally
|
||||
files = [
|
||||
(f, full, os.stat(full))
|
||||
for f, full in files
|
||||
if os.path.isfile(full)
|
||||
]
|
||||
|
||||
if len(files) == 0:
|
||||
logger.warning("No export file to display in /dl")
|
||||
|
||||
return render_template("downloads.html", export_file_stats=files)
|
||||
|
||||
|
||||
@app.route("/stats")
|
||||
|
1
static/downloads/README.md
Normal file
1
static/downloads/README.md
Normal file
@ -0,0 +1 @@
|
||||
CSV exports of the database will be available here.
|
@ -11,6 +11,10 @@
|
||||
<p>Please let me know if you used the database in a project!</p>
|
||||
<p>The entire database is exported to CSV regularly</p>
|
||||
|
||||
{% if not export_file_stats %}
|
||||
<br/>
|
||||
<p><em>No files available.</em></p>
|
||||
{% else %}
|
||||
<table class="table table-striped">
|
||||
|
||||
<thead>
|
||||
@ -22,16 +26,17 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% if export_file_stats %}
|
||||
{% for name, path, stat in export_file_stats %}
|
||||
<tr>
|
||||
<td><a href="static/out.csv.xz">out.csv.xz</a></td>
|
||||
<td>{{ export_file_stats.st_size |filesizeformat }}</td>
|
||||
<td>{{ export_file_stats.st_mtime|datetime_format }} UTC</td>
|
||||
<td><a href="{{ path }}">{{ name }}</a></td>
|
||||
<td>{{ stat.st_size |filesizeformat }}</td>
|
||||
<td>{{ stat.st_mtime|datetime_format }} UTC</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user