diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-01-15 01:17:57 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-01-15 01:17:57 -0800 |
commit | 985d0f42b38029abfbdd4fd0699cdee9517b066b (patch) | |
tree | f0aaf0bb2ec4d80b326bc4d18902eb24284cb061 | |
parent | 78472e82535da109f63e1b5c5ce8465016c2f8cc (diff) | |
download | fatcat-scholar-985d0f42b38029abfbdd4fd0699cdee9517b066b.tar.gz fatcat-scholar-985d0f42b38029abfbdd4fd0699cdee9517b066b.zip |
make fmt
-rw-r--r-- | fatcat_scholar/schema.py | 12 | ||||
-rw-r--r-- | fatcat_scholar/web.py | 21 |
2 files changed, 19 insertions, 14 deletions
diff --git a/fatcat_scholar/schema.py b/fatcat_scholar/schema.py index 131cf74..b5a4749 100644 --- a/fatcat_scholar/schema.py +++ b/fatcat_scholar/schema.py @@ -114,11 +114,11 @@ class ScholarBiblio(BaseModel): """ if style == "bibtex": type_map = { - 'article-journal': 'article', - 'conference-paper': 'proceedings', - 'thesis': 'phdthesis', - 'book': 'book', - None: 'unpublished', + "article-journal": "article", + "conference-paper": "proceedings", + "thesis": "phdthesis", + "book": "book", + None: "unpublished", } val = f"@{type_map.get(self.release_type, 'unpublished')}{{{self.release_ident},\n" val += f" title = {{{self.title}}}\n" @@ -142,7 +142,7 @@ class ScholarBiblio(BaseModel): val = ", ".join(self.contrib_names) if val: val += ". " - val += f" \"self.title.\" " + val += f' "self.title." ' if self.container_name: val += self.container_name if self.volume and self.issue: diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index fe2ad90..5d978d1 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -82,6 +82,7 @@ api = APIRouter() async def home() -> Any: return {"endpoints": {"/": "this", "/search": "fulltext search"}} + class HitsModel(BaseModel): count_returned: int count_found: int @@ -91,6 +92,7 @@ class HitsModel(BaseModel): query_wall_time_ms: int results: List[ScholarDoc] + @api.get("/search", operation_id="get_search", response_model=HitsModel) async def search(query: FulltextQuery = Depends(FulltextQuery)) -> FulltextHits: hits: Optional[FulltextHits] = None @@ -106,7 +108,7 @@ async def search(query: FulltextQuery = Depends(FulltextQuery)) -> FulltextHits: # remove internal context from hit objects for doc in hits.results: - doc.pop('_obj', None) + doc.pop("_obj", None) return hits @@ -267,9 +269,13 @@ app.include_router(api) app.mount("/static", StaticFiles(directory="fatcat_scholar/static"), name="static") + @app.get("/favicon.ico", include_in_schema=False) async def favicon(): - return FileResponse("fatcat_scholar/static/ia-favicon.ico", media_type="image/x-icon") + return FileResponse( + "fatcat_scholar/static/ia-favicon.ico", media_type="image/x-icon" + ) + ROBOTS_ALLOW = open("fatcat_scholar/static/robots.allow.txt", "r").read() ROBOTS_DISALLOW = open("fatcat_scholar/static/robots.disallow.txt", "r").read() @@ -282,6 +288,7 @@ async def robots_txt(response_class: Any = PlainTextResponse) -> Any: else: return PlainTextResponse(ROBOTS_DISALLOW) + @app.exception_handler(StarletteHTTPException) async def http_exception_handler(request: Request, exc: StarletteHTTPException) -> Any: """ @@ -303,13 +310,11 @@ async def http_exception_handler(request: Request, exc: StarletteHTTPException) status_code=exc.status_code, ) else: - resp = {'status_code': exc.status_code} + resp = {"status_code": exc.status_code} if exc.detail: - resp['detail'] = exc.detail - return JSONResponse( - status_code=exc.status_code, - content=resp, - ) + resp["detail"] = exc.detail + return JSONResponse(status_code=exc.status_code, content=resp,) + # configure middleware |