Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
e681fab
0
Parent(s):
feat: initial trustpilot proxy
Browse files- Dockerfile +6 -0
- README.md +8 -0
- app.py +42 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY requirements.txt .
|
| 4 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
+
COPY app.py .
|
| 6 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Trustpilot Proxy
|
| 3 |
+
emoji: ⭐
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Response
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
import httpx
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
app.add_middleware(
|
| 9 |
+
CORSMiddleware,
|
| 10 |
+
allow_origins=["https://collectionsdarchitectes.fr"],
|
| 11 |
+
allow_methods=["GET"],
|
| 12 |
+
allow_headers=["*"],
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
API_KEY = os.environ.get("TRUSTPILOT_API_KEY")
|
| 16 |
+
BUSINESS_UNIT_ID = os.environ.get("TRUSTPILOT_BUSINESS_UNIT_ID")
|
| 17 |
+
BASE_URL = "https://api.trustpilot.com/v1"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@app.get("/business")
|
| 21 |
+
async def get_business():
|
| 22 |
+
async with httpx.AsyncClient() as client:
|
| 23 |
+
r = await client.get(
|
| 24 |
+
f"{BASE_URL}/business-units/{BUSINESS_UNIT_ID}",
|
| 25 |
+
params={"apikey": API_KEY},
|
| 26 |
+
)
|
| 27 |
+
return Response(content=r.content, media_type="application/json", status_code=r.status_code)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.get("/reviews")
|
| 31 |
+
async def get_reviews(perPage: int = 6, stars: str = "4,5"):
|
| 32 |
+
async with httpx.AsyncClient() as client:
|
| 33 |
+
r = await client.get(
|
| 34 |
+
f"{BASE_URL}/business-units/{BUSINESS_UNIT_ID}/reviews",
|
| 35 |
+
params={
|
| 36 |
+
"apikey": API_KEY,
|
| 37 |
+
"perPage": perPage,
|
| 38 |
+
"orderBy": "createdat.desc",
|
| 39 |
+
"stars": stars,
|
| 40 |
+
},
|
| 41 |
+
)
|
| 42 |
+
return Response(content=r.content, media_type="application/json", status_code=r.status_code)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
httpx
|