Scripts to generate the file and api update to grab what exists

This commit is contained in:
zandercymatics 2023-11-21 14:28:31 -07:00
parent e52954f984
commit bca311b8ca
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 145 additions and 35 deletions

View file

@ -1,7 +1,7 @@
"""Internal API views"""
from django.apps import apps
from django.views.decorators.http import require_http_methods
from django.http import JsonResponse
from django.http import FileResponse, HttpResponse, JsonResponse
import requests
@ -89,3 +89,26 @@ def available(request, domain=""):
return JsonResponse({"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]})
except Exception:
return JsonResponse({"available": False, "message": DOMAIN_API_MESSAGES["error"]})
@require_http_methods(["GET"])
@login_not_required
def get_current_full(request):
# Open the CSV file
file_path = './migrationData/current-full.csv'
return serve_file(file_path)
@require_http_methods(["GET"])
@login_not_required
def get_current_federal(request):
# Open the CSV file
file_path = './migrationData/current-federal.csv'
return serve_file(file_path)
def serve_file(file_path):
"""Downloads a file based on a given filepath. Returns a 404 if not found."""
if os.path.exists(file_path):
# Serve the CSV file
response = FileResponse(open(file_path, 'rb'))
return response
else:
return HttpResponse("File not found", status=404)