Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MongoDB #59

Merged
merged 6 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions API/MongoDB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from dataclasses import dataclass


@dataclass
class Councilor:
sdName: str
sggName: str
wiwName: str
name: str
gender: str
birthday: str
age: int
jobId: int
job: str
eduId: int
edu: str

@classmethod
def from_dict(cls, data: dict):
return cls(
sdName=data.get("sdName"),
sggName=data.get("sggName"),
wiwName=data.get("wiwName"),
name=data.get("name"),
gender=data.get("gender"),
birthday=data.get("birthday"),
age=int(data.get("age")),
jobId=int(data.get("jobId")),
job=data.get("job"),
eduId=int(data.get("eduId")),
edu=data.get("edu"),
)

def to_dict(self):
return {
"sdName": self.sdName,
"sggName": self.sggName,
"wiwName": self.wiwName,
"name": self.name,
"gender": self.gender,
"birthday": self.birthday,
"age": self.age,
"jobId": self.jobId,
"job": self.job,
"eduId": self.eduId,
"edu": self.edu,
}
1 change: 1 addition & 0 deletions API/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os, requests, sys
import xml.etree.ElementTree as ET
from typing import List
import argparse

from configurations.secrets import OpenDataPortalSecrets
from .utils import save_to_excel, getLocalMetroMap
Expand Down
17 changes: 10 additions & 7 deletions API/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ def save_to_mongo(data: List[dict], sgTypecode: str) -> None:
main_collection = db["local_councilor"]

local_metro_map = getLocalMetroMap()

print(len(data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 print는 디버깅용인 것 같은데, 혹시 지워도 괜찮으면 제가 커밋해서 올려두겠습니다~

# TODO: Support other types of councils
if sgTypecode == "6":
for entry in data:
district_id = local_metro_map[(entry["sdName"], entry["wiwName"])][
"local_id"
]

if not (entry["sdName"], entry["wiwName"]) in local_metro_map:
print(
f"Warning: '{entry['sdName']} {entry['wiwName']}'에 해당하는 지역 ID가 존재하지 않습니다."
)
continue
district_id = local_metro_map[(entry["sdName"], entry["wiwName"])]
if district_id:
main_collection.update_one(
{
"name": entry["name"],
"localId": district_id,
"local_id": district_id["local_id"],
"metro_id": district_id["metro_id"],
},
{"$push": Councilor.from_dict(entry)},
{"$set": Councilor.from_dict(entry).to_dict()},
upsert=True,
)
else:
Expand Down
1 change: 0 additions & 1 deletion API/votecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
xml_data = response.content.decode("utf-8")
# Parse the XML data
root = ET.fromstring(xml_data)

# Find all elements where sgTypecode is equal to INPUT and extract their sgId values
sgIds = set()
for code in input("Input the number of sgTypecode: ").split(","):
Expand Down