Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
added a bulk download option. This closes Code4HR/open-health-inspect…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttavenner committed Jul 15, 2014
1 parent c8b7368 commit c475bed
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
17 changes: 16 additions & 1 deletion API.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from math import radians, cos, sin, atan2, sqrt
from bson.objectid import ObjectId
from flask import Flask, Response, url_for, request, current_app
from flask import Flask, Response, url_for, request, current_app, render_template
from functools import wraps
from collections import OrderedDict
from datetime import datetime
Expand Down Expand Up @@ -286,5 +286,20 @@ def api_lives_file(locality):
404


@app.route('/bulk/')
def api_bulk_file():
path = os.path.join(os.path.dirname(__file__), 'bulk')
files = os.listdir(path)
file_list = []

for item in files:
stats = os.stat(os.path.join(path, item))

file_list.append({'name': item,
'size': '{:,}'.format(stats.st_size)+' bytes',
'date': datetime.strftime(datetime.fromtimestamp(stats.st_mtime), '%b %d, %Y')})

return render_template('bulk_list.html', tree=file_list)

if __name__ == '__main__':
app.run()
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ Can be searched by adding any or all of the following parameters:
<tr>
<td colspan=2>After a file is requested through /lives/, it will be available at this URL.</td>
</tr>
<tr>
<td>/bulk/</td>
</tr>
<tr>
<td colspan=2>Provides bulk downloads of all data in the inspection database. Currently the data is only provided in JSON files but other formats will likely be available in the future. The data is currently updated weekly following a run of the <a href="https://github.com/c4hrva/open-health-inspection-scraper">Scraper</a>. The files are produced using the mongoexport command line tool.</td>
</tr>
</table>
30 changes: 30 additions & 0 deletions templates/bulk_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<head>
<title>Bulk Exports</title>
</head>
<body>
<h2>Bulk Downloads of Virginia Health Inspection Data</h2>
<table style='width: 30%;'>
<tr>
<th>File Name</th>
<th>File Size</th>
<th>File Creation Date</th>
</tr>
{%- for item in tree %}
{%- if item -%}
<tr>
<td>
<a href="{{item.name}}">{{item.name}}</a>
</td>
<td>
{{item['size']}}
</td>
<td>
{{item.date}}
</td>
</tr>
{%- endif %}
{%- endfor %}
</table>
</body>
</html>

0 comments on commit c475bed

Please sign in to comment.