Spaces:
Sleeping
Sleeping
Commit ·
f597c94
1
Parent(s): 29009fc
Make it more user interactive API
Browse files
main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
-
from fastapi.
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import requests
|
| 5 |
import pandas as pd
|
|
@@ -12,7 +12,11 @@ from sheets_client import add_subscriber_to_sheet
|
|
| 12 |
import random
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
origins = ["*"]
|
| 18 |
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
|
@@ -112,6 +116,34 @@ def generate_mock_topmovers_data():
|
|
| 112 |
high_demand = [{"city": c, "flights": random.randint(30, 120), "change": f"+{random.randint(8, 25)}%"} for c in cities]
|
| 113 |
return {"priceDrops": price_drops, "highDemand": high_demand}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
@app.post("/api/newsletter")
|
| 116 |
def handle_newsletter(payload: NewsletterPayload):
|
| 117 |
success, message = add_subscriber_to_sheet(
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import requests
|
| 5 |
import pandas as pd
|
|
|
|
| 12 |
import random
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
+
app = FastAPI(
|
| 16 |
+
title="Aussie Backpacker Flow API",
|
| 17 |
+
description="Provides flight demand analysis and AI-powered insights for Australian hostels.",
|
| 18 |
+
version="1.0.0"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
origins = ["*"]
|
| 22 |
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
|
|
|
| 116 |
high_demand = [{"city": c, "flights": random.randint(30, 120), "change": f"+{random.randint(8, 25)}%"} for c in cities]
|
| 117 |
return {"priceDrops": price_drops, "highDemand": high_demand}
|
| 118 |
|
| 119 |
+
@app.get("/", response_class=HTMLResponse)
|
| 120 |
+
def read_root():
|
| 121 |
+
html_content = """
|
| 122 |
+
<html>
|
| 123 |
+
<head>
|
| 124 |
+
<title>Aussie Backpacker Flow API</title>
|
| 125 |
+
<style>
|
| 126 |
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: #0d1117; color: #c9d1d9; line-height: 1.6; padding: 40px; }
|
| 127 |
+
.container { max-width: 700px; margin: auto; background-color: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 40px; text-align: center; }
|
| 128 |
+
h1 { color: #58a6ff; }
|
| 129 |
+
code { background-color: #30363d; padding: 4px 8px; border-radius: 6px; font-family: "SF Mono", "Consolas", monospace; }
|
| 130 |
+
a { color: #58a6ff; text-decoration: none; }
|
| 131 |
+
.status { display: inline-block; background-color: #238636; color: white; padding: 5px 15px; border-radius: 20px; font-weight: bold; }
|
| 132 |
+
</style>
|
| 133 |
+
</head>
|
| 134 |
+
<body>
|
| 135 |
+
<div class="container">
|
| 136 |
+
<h1>Aussie Backpacker Flow API</h1>
|
| 137 |
+
<p class="status">API is running!</p>
|
| 138 |
+
<p>This is the backend server for the flight demand analysis tool.</p>
|
| 139 |
+
<p>To see the interactive documentation for all endpoints, visit <a href="/docs">/docs</a>.</p>
|
| 140 |
+
<p>The main data endpoint is <code>/api/dashboard-data</code>.</p>
|
| 141 |
+
</div>
|
| 142 |
+
</body>
|
| 143 |
+
</html>
|
| 144 |
+
"""
|
| 145 |
+
return HTMLResponse(content=html_content)
|
| 146 |
+
|
| 147 |
@app.post("/api/newsletter")
|
| 148 |
def handle_newsletter(payload: NewsletterPayload):
|
| 149 |
success, message = add_subscriber_to_sheet(
|