mirror of
https://github.com/its-michaelroy/Deep-Impact.git
synced 2026-06-04 02:20:41 +00:00
add the NASA Sentry api call to the backend
This commit is contained in:
6
backend/deep_impact_proj/.env.sample
Normal file
6
backend/deep_impact_proj/.env.sample
Normal file
@@ -0,0 +1,6 @@
|
||||
SECRET_KEY=<"Your Django Secret Key">
|
||||
SENTRY_API_KEY=<"Your NASA Sentry API Key">
|
||||
OPENAI_API_KEY=<"Your OpenAI API Key">
|
||||
HOST_CLIENT=<"Your FrontEnd URL">
|
||||
ALLOWED_HOSTS=<"Your Server URL">
|
||||
DEBUG=<"True for Deployment | False for Development">
|
||||
2
backend/deep_impact_proj/.gitignore
vendored
Normal file
2
backend/deep_impact_proj/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
.venv
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,7 @@
|
||||
from django.urls import path
|
||||
from .views import (
|
||||
Sentry,
|
||||
OpenAI,
|
||||
)
|
||||
from .views import Sentry, OpenAI
|
||||
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('sentry/', Sentry.as_view(), name='sentry'),
|
||||
|
||||
23
backend/deep_impact_proj/api_app/utils.py
Normal file
23
backend/deep_impact_proj/api_app/utils.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
import os
|
||||
import requests
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import (
|
||||
HTTP_200_OK,
|
||||
HTTP_204_NO_CONTENT,
|
||||
HTTP_201_CREATED,
|
||||
HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
|
||||
sentry_api_key = os.environ.get("SENTRY_API_KEY")
|
||||
|
||||
def get_sentry():
|
||||
try:
|
||||
response = requests.get(f'https://api.nasa.gov/neo/rest/v1/neo/browse?api_key={sentry_api_key}')
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return Response(data, status=HTTP_200_OK)
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
return Response(e, status=HTTP_400_BAD_REQUEST)
|
||||
@@ -1,8 +1,26 @@
|
||||
from django.shortcuts import render
|
||||
from django.core.exceptions import ValidationError
|
||||
import os
|
||||
import requests
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import (
|
||||
HTTP_200_OK,
|
||||
HTTP_204_NO_CONTENT,
|
||||
HTTP_201_CREATED,
|
||||
HTTP_400_BAD_REQUEST
|
||||
)
|
||||
from .utils import get_sentry
|
||||
|
||||
sentry_api_key = os.environ.get("SENTRY_API_KEY")
|
||||
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class Sentry:
|
||||
pass
|
||||
class Sentry(APIView):
|
||||
def get(self, request):
|
||||
return get_sentry()
|
||||
|
||||
class OpenAI:
|
||||
|
||||
class OpenAI(APIView):
|
||||
pass
|
||||
|
||||
BIN
backend/deep_impact_proj/db.sqlite3
Normal file
BIN
backend/deep_impact_proj/db.sqlite3
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,11 @@ https://docs.djangoproject.com/en/5.0/ref/settings/
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
@@ -20,12 +25,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-3(n0mvl^xk3rjak+runl7#wbx1vr1y+y17dber5zl5ab3x6_hy'
|
||||
SECRET_KEY = os.environ.get("SECRET_KEY")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = os.environ.get("DEBUG")
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = [os.environ.get("ALLOWED_HOSTS"), "localhost"]
|
||||
|
||||
|
||||
# Application definition
|
||||
@@ -37,12 +42,15 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'corsheaders',
|
||||
'api_app',
|
||||
'rest_framework',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
@@ -52,6 +60,12 @@ MIDDLEWARE = [
|
||||
|
||||
ROOT_URLCONF = 'deep_impact_proj.urls'
|
||||
|
||||
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [os.environ.get("HOST_CLIENT")]
|
||||
|
||||
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
|
||||
17
backend/deep_impact_proj/requirements.txt
Normal file
17
backend/deep_impact_proj/requirements.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
asgiref==3.8.1
|
||||
certifi==2024.2.2
|
||||
charset-normalizer==3.3.2
|
||||
click==8.1.7
|
||||
Django==5.0.6
|
||||
django-cors-headers==4.2.0
|
||||
djangorestframework==3.15.1
|
||||
gunicorn==22.0.0
|
||||
h11==0.14.0
|
||||
idna==3.7
|
||||
packaging==24.0
|
||||
python-dotenv==1.0.1
|
||||
requests==2.31.0
|
||||
sqlparse==0.5.0
|
||||
urllib3==2.2.1
|
||||
uvicorn==0.29.0
|
||||
whitenoise==6.6.0
|
||||
@@ -3,7 +3,7 @@ import { Stage, Layer, Circle, Text, Line } from 'react-konva';
|
||||
import { Slider, Button } from '@mui/material';
|
||||
import axios from 'axios';
|
||||
|
||||
const API_KEY = 'LF7i77oqghRiq54HEFJh991WgjHcKsETP9D5ofsg';
|
||||
|
||||
const EARTH_RADIUS_KM = 6371; // Earth's radius in kilometers
|
||||
const EARTH_DISPLAY_SCALE = 0.01; // Display scale for Earth
|
||||
const ASTEROID_DISPLAY_SCALE = 0.3; // Display scale for asteroids
|
||||
@@ -37,9 +37,9 @@ function Scenario() {
|
||||
const [timeStep, setTimeStep] = useState(100); // State for time step
|
||||
|
||||
useEffect(() => {
|
||||
const fetchAsteroids = async () => {
|
||||
const fetchAsteroids = async (self, request) => {
|
||||
try {
|
||||
const response = await axios.get(`https://api.nasa.gov/neo/rest/v1/neo/browse?api_key=${API_KEY}`);
|
||||
const response = await axios.get(`http://localhost:8000/api/sentry/`);
|
||||
asteroidsData.current = response.data.near_earth_objects;
|
||||
setAsteroidData(0); // Set initial asteroid
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user