Skip to content

Commit

Permalink
Formatted with black
Browse files Browse the repository at this point in the history
  • Loading branch information
happycastle114 authored and github-actions[bot] committed Nov 17, 2023
1 parent 0864158 commit 9451b0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 0 additions & 1 deletion API/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def fetch_all_data(
data_list = fetch_all_data(sgIds, args.sgTypecode, drop_columns=drop_columns)
print(getLocalMetroMap())


if args.save_method == "excel":
save_to_excel(data_list, args.sgTypecode, is_elected=True)
elif args.save_method == "mongo":
Expand Down
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 9451b0f

Please sign in to comment.