From ad99ac11a56da5204b934c45a1871b4a8c1592fb Mon Sep 17 00:00:00 2001 From: Illia Kaialainien Date: Mon, 8 Jan 2024 22:07:23 +0200 Subject: [PATCH] added docstrings --- fill_db.py | 5 ++++- main.py | 1 + server/app.py | 5 ----- server/database.py | 3 +-- server/models/search_result.py | 1 - 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fill_db.py b/fill_db.py index d761a31..ee7caa7 100644 --- a/fill_db.py +++ b/fill_db.py @@ -4,14 +4,17 @@ async def fill(): + """Dump news corresponding to laptops""" with open('laptop_models.json') as f: laptops = json.load(f) - print('[INFO] loaded laptops') + print('[INFO] loaded laptops') + for i, laptop in enumerate(laptops): name = (laptop.get('producer') + ' ' + laptop.get('model')).lower() print(f'[INFO] process {i} laptop') await update_search_results(name) + if __name__ == '__main__': import asyncio asyncio.run(fill()) diff --git a/main.py b/main.py index 11f8970..bddd196 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +"""start app""" import uvicorn diff --git a/server/app.py b/server/app.py index 85c9385..1bf3fa1 100644 --- a/server/app.py +++ b/server/app.py @@ -5,8 +5,3 @@ app = FastAPI() app.include_router(SearchResultRouter, tags=["News"], prefix="/news") - - -@app.get('/', tags=['Root']) -async def read_root(): - return {'message': 'Welcome!'} diff --git a/server/database.py b/server/database.py index 4669695..9d52581 100644 --- a/server/database.py +++ b/server/database.py @@ -11,12 +11,11 @@ MONGO_DETAILS = 'mongodb://mongodb:27017' client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_DETAILS) db = client.lappy - search_results_collection = db.get_collection('search_results') def search_results_helper(search_result): - """Take each article and convert it to JSONable format""" + """Convert each article to JSONable format""" return { "id": str(search_result["_id"]), "link": search_result["link"], diff --git a/server/models/search_result.py b/server/models/search_result.py index 771f4d7..0b6af0d 100644 --- a/server/models/search_result.py +++ b/server/models/search_result.py @@ -12,7 +12,6 @@ class ArticleModel(BaseModel): image: HttpUrl | None = None date: datetime | None = None description: str = "" - tags: set[str] = set() class SearchResponseModel(BaseModel):