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): diff --git a/server/routes/search_result.py b/server/routes/search_result.py index 00db0c0..05e5910 100644 --- a/server/routes/search_result.py +++ b/server/routes/search_result.py @@ -38,19 +38,19 @@ async def get_search_results(find: Annotated[str | None, Query(description='Writ return {'count': count, 'results': results} -@router.get("/{id}", status_code=status.HTTP_200_OK, response_model=ExtendArticleModel) -async def get_article(id: str): +@router.get("/{id_}", status_code=status.HTTP_200_OK, response_model=ExtendArticleModel) +async def get_article(id_: str): """Get concrete article with content Find article by ID in database and if it exists, check if it has content in 'content' field. If it is, return it, else scrap this content. If article is not exist in db, return 404. """ - result = await retrieve_search_result_by_id(id) + result = await retrieve_search_result_by_id(id_) if result: if not result['content']: content = scrap_content(result['link']) - result = await update_content_of_article(id, content) + result = await update_content_of_article(id_, content) return result else: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Item not found")