diff --git a/API/MongoDB.py b/API/MongoDB.py new file mode 100644 index 0000000..d58ca18 --- /dev/null +++ b/API/MongoDB.py @@ -0,0 +1,32 @@ +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=data.get("age"), + jobId=data.get("jobId"), + job=data.get("job"), + eduId=data.get("eduId"), + edu=data.get("edu"), + ) diff --git a/API/candidate.py b/API/candidate.py index 745d96a..7ec6743 100644 --- a/API/candidate.py +++ b/API/candidate.py @@ -3,6 +3,8 @@ import os, requests, sys import xml.etree.ElementTree as ET from typing import List +from .MongoDB import Councilor +import argparse from configurations.secrets import OpenDataPortalSecrets from .utils import save_to_excel @@ -39,11 +41,10 @@ def fetch_data( data_list = [] for item in root.findall(".//item"): data_entry = {child.tag: child.text for child in item} - for column in drop_columns: data_entry.pop(column) - data_list.append(data_entry) + data_list.append(Councilor.from_dict(data_entry)) return data_list