⚡ Live Interactive Code Sandbox: AI Dev Tool: Magnitude 74 Earthquake
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```python # AI Dev Tool: Earthquake Data Ingestion and Analysis API # ===================================================== # This API integrates with the United States Geological Survey (USGS) API # to fetch earthquake data and perform analysis on it. from fastapi import FastAPI, HTTPException from pydantic import BaseModel from typing import List, Optional import requests import pandas as pd app = FastAPI() # Define the Earthquake model class Earthquake(BaseModel): """Earthquake data model""" magnitude: float location: str depth: float date: str # Define the API endpoint to fetch earthquake data @app.get("/earthquakes", response_model=List[Earthquake]) async def get_earthquakes(): """ Fetches earthquake data from the USGS API """ try: response = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2022-01-01&endtime=2022-01-02") data = response.json() earthquakes = [] for feature in data["features"]: earthquake = Earthquake( magnitude=feature["properties"]["mag"], location=
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...