Spaces:
Sleeping
Sleeping
Commit ·
2d82c8b
1
Parent(s): 7d4da7e
Uploading the app
Browse files- Dockerfile +10 -0
- main.py +32 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt requirements.txt
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Dict
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# In-memory storage for now
|
| 9 |
+
bus_locations: Dict[str, dict] = {}
|
| 10 |
+
|
| 11 |
+
class Location(BaseModel):
|
| 12 |
+
_type: str
|
| 13 |
+
tid: str
|
| 14 |
+
lat: float
|
| 15 |
+
lon: float
|
| 16 |
+
tst: int
|
| 17 |
+
|
| 18 |
+
@app.post("/track")
|
| 19 |
+
async def track_location(loc: Location):
|
| 20 |
+
# Save by bus_id (tid)
|
| 21 |
+
bus_locations[loc.tid] = {
|
| 22 |
+
"lat": loc.lat,
|
| 23 |
+
"lon": loc.lon,
|
| 24 |
+
"timestamp": loc.tst,
|
| 25 |
+
"last_updated": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(loc.tst))
|
| 26 |
+
}
|
| 27 |
+
print(f"[{loc.tid}] → ({loc.lat}, {loc.lon}) @ {loc.tst}")
|
| 28 |
+
return {"status": "ok"}
|
| 29 |
+
|
| 30 |
+
@app.get("/locations")
|
| 31 |
+
def get_all_locations():
|
| 32 |
+
return bus_locations
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|