Skip to content

Commit

Permalink
Merge branch 'API-model' of https://github.com/NewWays-TechForImpactK…
Browse files Browse the repository at this point in the history
  • Loading branch information
happycastle114 committed Nov 17, 2023
2 parents d020652 + 9451b0f commit 92f4c92
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
3 changes: 2 additions & 1 deletion API/elected.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from .utils import save_to_excel, save_to_mongo, getLocalMetroMap


BASE_URL = "http://apis.data.go.kr/9760000/WinnerInfoInqireService2/getWinnerInfoInqire"
BASE_URL = "http://apis.data.go.kr/9760000/WinnerInfoInqireService2/getWinnerInfoInqire"


def fetch_data(
sgId: str,
Expand Down
42 changes: 28 additions & 14 deletions API/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,34 @@ def save_to_mongo(data: List[dict], sgTypecode: str) -> None:

print(f"데이터를 성공적으로 MongoDB '{main_collection.name}' 컬렉션에 저장하였습니다.")


def getLocalMetroMap() -> Dict[str, str]:
db = client["district"]
result = db["local_district"].aggregate([{
"$lookup": {
"from": "metro_district",
"localField": "sdName",
"foreignField": "name_ko",
"as": "productInfo"
result = db["local_district"].aggregate(
[
{
"$lookup": {
"from": "metro_district",
"localField": "sdName",
"foreignField": "name_ko",
"as": "productInfo",
}
},
{"$unwind": "$productInfo"},
{
"$project": {
"cid": 1,
"metro_id": "$productInfo.metro_id",
"sdName": 1,
"wiwName": 1,
}
},
]
)
return {
(item["sdName"], item["wiwName"]): {
"local_id": item["cid"],
"metro_id": item["metro_id"],
}
}, { "$unwind": "$productInfo" }, { "$project": {
"cid": 1,
"metro_id": "$productInfo.metro_id",
"sdName": 1,
"wiwName": 1,
} }])
return {(item["sdName"], item["wiwName"]): {"local_id": item["cid"], "metro_id": item["metro_id"]} for item in result}

for item in result
}

0 comments on commit 92f4c92

Please sign in to comment.