From 2bb5fb0daf9de1b4221c744e26efab5123c500cd Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Fri, 1 Dec 2023 00:24:31 +0900 Subject: [PATCH] Fix: Year --- routers/scrapResultNational.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/routers/scrapResultNational.py b/routers/scrapResultNational.py index 045307c..9eaec53 100644 --- a/routers/scrapResultNational.py +++ b/routers/scrapResultNational.py @@ -242,13 +242,16 @@ async def getNationalTemplateData( ) years.sort() assert len(years) >= 2 - + year_index = years.index(year) + if year_index == 0: + return NO_DATA_ERROR_RESPONSE + current_elected = client.stats_db["party_hist"].find( { "councilorType": "national_councilor", "level": 0, "is_elected": True, - "year": years[-1], + "year": years[year_index], }, { "_id": 0, @@ -263,7 +266,7 @@ async def getNationalTemplateData( "councilorType": "national_councilor", "level": 0, "is_elected": False, - "year": years[-1], + "year": years[year_index], }, { "_id": 0, @@ -278,7 +281,7 @@ async def getNationalTemplateData( "councilorType": "national_councilor", "level": 0, "is_elected": True, - "year": years[-2], + "year": years[year_index - 1], }, { "_id": 0,