Skip to content

Commit

Permalink
[analysis] metro_council도 가능하도록. [API] sgTypecode 복수개 주도록
Browse files Browse the repository at this point in the history
  • Loading branch information
Re-st committed Nov 27, 2023
1 parent 221da39 commit 2eba982
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 223 deletions.
20 changes: 11 additions & 9 deletions API/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def fetch_all_data(

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="공공데이터포털 API로부터 후보자 정보를 가져옵니다.")
parser.add_argument("sgTypecode", type=str, help="원하는 sgTypecode 하나를 입력하세요")
parser.add_argument("sgTypecodes", type=str, help="원하는 sgTypecode를 ','로 구분하여 입력하세요")
parser.add_argument("sgIds", type=str, help="원하는 sgId를 ','로 구분하여 입력하세요")
parser.add_argument(
"--drop-columns",
Expand All @@ -84,11 +84,13 @@ def fetch_all_data(
sgIds = args.sgIds.split(",")
drop_columns = args.drop_columns.split(",") if args.drop_columns else []

data_list = fetch_all_data(sgIds, args.sgTypecode, drop_columns=drop_columns)

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, CANDIDATE_TYPECODE_TYPE[args.sgTypecode]
)
data_list = fetch_all_data(sgIds, args.sgTypecodes, drop_columns=drop_columns)
for sgTypecode in args.sgTypecodes.split(","):
if sgTypecode not in SG_TYPECODE:
raise ValueError(f"Invalid sgTypecode: {sgTypecode}")
if args.save_method == "excel":
save_to_excel(data_list, sgTypecode, is_elected=False)
elif args.save_method == "mongo":
save_to_mongo(
data_list, sgTypecode, CANDIDATE_TYPECODE_TYPE[sgTypecode]
)
26 changes: 15 additions & 11 deletions API/elected.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ def fetch_data(


def fetch_all_data(
sgIds: List[str], sgTypecode: str, drop_columns: List[str]
sgIds: List[str], sgTypecodes: str, drop_columns: List[str]
) -> List[dict]:
data_list = []
for sgId in sgIds:
data_list.extend(fetch_data(sgId, sgTypecode, drop_columns=drop_columns))
for sgTypecode in sgTypecodes.split(","):
for sgId in sgIds:
data_list.extend(fetch_data(sgId, sgTypecode, drop_columns=drop_columns))

return data_list


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="공공데이터포털 API로부터 당선자 정보를 가져옵니다.")
parser.add_argument("sgTypecode", type=str, help="원하는 sgTypecode 하나를 입력하세요")
parser.add_argument("sgTypecodes", type=str, help="원하는 sgTypecode를 ','로 구분하여 입력하세요")
parser.add_argument("sgIds", type=str, help="원하는 sgId를 ','로 구분하여 입력하세요")
parser.add_argument(
"--drop-columns",
Expand All @@ -82,10 +83,13 @@ def fetch_all_data(
sgIds = args.sgIds.split(",")
drop_columns = args.drop_columns.split(",") if args.drop_columns else []

data_list = fetch_all_data(sgIds, args.sgTypecode, drop_columns=drop_columns)
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, ELECTED_TYPECODE_TYPE[args.sgTypecode]
)
data_list = fetch_all_data(sgIds, args.sgTypecodes, drop_columns=drop_columns)
for sgTypecode in args.sgTypecodes.split(","):
if sgTypecode not in SG_TYPECODE:
raise ValueError(f"Invalid sgTypecode: {sgTypecode}")
if args.save_method == "excel":
save_to_excel(data_list, sgTypecode, is_elected=True)
elif args.save_method == "mongo":
save_to_mongo(
data_list, sgTypecode, ELECTED_TYPECODE_TYPE[sgTypecode]
)
3 changes: 3 additions & 0 deletions analysis/age/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
공공데이터포털 API로 수집한 데이터를 분석하기 위한 패키지입니다.
"""
class BasicArgument:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
Loading

0 comments on commit 2eba982

Please sign in to comment.