Skip to content

Commit

Permalink
feat(API): add candidate collection for API
Browse files Browse the repository at this point in the history
  • Loading branch information
keonly authored and Re-st committed Nov 23, 2023
1 parent 5c3b15e commit c5e217b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion API/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@
"10": "교육의원",
"11": "교육감",
}
SG_TYPECODE_TYPE = {
ELECTED_TYPECODE_TYPE = {
"2": CouncilType.NATIONAL_COUNCIL,
"3": CouncilType.METRO_LEADER,
"4": CouncilType.LOCAL_LEADER,
"5": CouncilType.METROPOLITAN_COUNCIL,
"6": CouncilType.LOCAL_COUNCIL,
"9": CouncilType.LOCAL_COUNCIL,
}
CANDIDATE_TYPECODE_TYPE = {
"2": CouncilType.NATIONAL_COUNCIL_CAND,
"5": CouncilType.METROPOLITAN_COUNCIL_CAND,
"6": CouncilType.LOCAL_COUNCIL_CAND,
"9": CouncilType.LOCAL_COUNCIL_CAND,
}
3 changes: 2 additions & 1 deletion API/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from configurations.secrets import OpenDataPortalSecrets
from .utils import save_to_excel, save_to_mongo, getLocalMetroMap
from . import SG_TYPECODE, CANDIDATE_TYPECODE_TYPE


BASE_URL = "http://apis.data.go.kr/9760000/PofelcddInfoInqireService/getPofelcddRegistSttusInfoInqire"
Expand Down Expand Up @@ -88,4 +89,4 @@ def fetch_all_data(
if args.save_method == "excel":
save_to_excel(data_list, args.sgTypecode, is_elected=False)
elif args.save_method == "mongo":
save_to_mongo(data_list, args.sgTypecode, "local_councilor_cand")
save_to_mongo(data_list, args.sgTypecode, CANDIDATE_TYPECODE_TYPE[args.sgTypecode])
3 changes: 2 additions & 1 deletion API/elected.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from configurations.secrets import OpenDataPortalSecrets
from .utils import save_to_excel, save_to_mongo, getLocalMetroMap
from . import SG_TYPECODE, ELECTED_TYPECODE_TYPE


BASE_URL = "http://apis.data.go.kr/9760000/WinnerInfoInqireService2/getWinnerInfoInqire"
Expand Down Expand Up @@ -85,4 +86,4 @@ def fetch_all_data(
if args.save_method == "excel":
save_to_excel(data_list, args.sgTypecode, is_elected=True)
elif args.save_method == "mongo":
save_to_mongo(data_list, args.sgTypecode, "local_councilor")
save_to_mongo(data_list, args.sgTypecode, ELECTED_TYPECODE_TYPE[args.sgTypecode])
2 changes: 1 addition & 1 deletion API/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
from typing import List, Optional, Dict

from . import BASE_DIR, SG_TYPECODE, SG_TYPECODE_TYPE
from . import BASE_DIR, SG_TYPECODE
from configurations.secrets import MongoDBSecrets
from db.client import client
from API.MongoDB import Councilor
Expand Down
6 changes: 6 additions & 0 deletions db/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ class CouncilType(str, Enum):
"""

LOCAL_COUNCIL = "local_councilor"
LOCAL_COUNCIL_CAND = "local_councilor_candidate"

NATIONAL_COUNCIL = "national_councilor"
NATIONAL_COUNCIL_CAND = "national_councilor_candidate"

METROPOLITAN_COUNCIL = "metropolitan_councilor"
METROPOLITAN_COUNCIL_CAND = "metropolitan_councilor_candidate"

LOCAL_LEADER = "local_leader"
METRO_LEADER = "metro_leader"
"""
Expand Down

0 comments on commit c5e217b

Please sign in to comment.