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

Commit

Permalink
file download route
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmas committed Jun 11, 2014
1 parent 5c8cf9c commit bf174d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions API.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ def api_lives(locality):
return json.dumps(l.metadata)


@app.route("/lives-file/<locality>.zip")
def api_lives_file(locality):
try:
with open(Lives.dataDir + "/" + locality + ".zip", "r") as lives_file:
return Response(lives_file.read(), mimetype="application/octet-stream")
except IOError as e:
return json.dumps({"status": "400", "message": "Couldn't find requested locality " + locality})


if __name__ == '__main__':
app.run()
10 changes: 5 additions & 5 deletions lives.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Lives:
def __init__(self, db, locality):
self.db = db
self.locality = locality
self.tmp_dir = self.dataDir + "/tmp"
self.metadata_file = "livesData/" + self.locality + ".json"
self.tmp_dir = Lives.dataDir + "/tmp"
self.metadata_file = Lives.dataDir + "/" + self.locality + ".json"
self.data = self.db.va.find({"locality": locality})

if not os.path.exists(self.dataDir):
os.makedirs(self.dataDir)
if not os.path.exists(Lives.dataDir):
os.makedirs(Lives.dataDir)
os.makedirs(self.tmp_dir)

self.metadata = self.__fetch_metadata()
Expand Down Expand Up @@ -87,7 +87,7 @@ def write_file(self):
i_writer.writerow([vendor["_id"],
inspection["date"].strftime("%Y%m%d")])

with zipfile.ZipFile(self.dataDir + "/" + self.locality + ".zip", 'w') as zip:
with zipfile.ZipFile(Lives.dataDir + "/" + self.locality + ".zip", 'w') as zip:
zip.write(businesses_path, self.locality + "/businesses.csv")
zip.write(inspections_path, self.locality + "/inspections.csv")

Expand Down

0 comments on commit bf174d6

Please sign in to comment.