Spaces:
Runtime error
Runtime error
File size: 1,298 Bytes
2b6d150 6a06a5e 2b6d150 6a06a5e 8ca5d50 2853f16 aa1499d 2b6d150 6a06a5e 2b6d150 8ca5d50 6a06a5e 7b2aa18 6a06a5e 7b2aa18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from fastapi import FastAPI
import pandas as pd
import os
from deta import Deta
from fastapi.responses import StreamingResponse, FileResponse
from io import BytesIO
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# load deta using
project_key = os.getenv("DETA_DRIVE_KEY")
deta = Deta(project_key)
drive = deta.Drive("stonk_events")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/files")
async def get_files(exchange: str = "US"):
"""
"""
# get files in deta
result = drive.list()
all_files = result.get("names")
paging = result.get("paging")
last = paging.get("last") if paging else None
while (last):
# provide last from previous call
result = drive.list(last=last)
all_files += result.get("names")
# update last
paging = result.get("paging")
last = paging.get("last") if paging else None
return all_files
# get file by name from deta /file/{id}
# reason it was likely failing is because of the response size limit
@app.get("/file/{id}")
async def get_file(id: str):
res = drive.get(id)
return StreamingResponse(res.iter_chunks(1024), media_type="application/pdf")
|