Skip to content

Commit

Permalink
Merge pull request #41 and resolve conflicts
Browse files Browse the repository at this point in the history
feat: add black formatter to CI
  • Loading branch information
Re-st authored Oct 13, 2023
2 parents 970120f + 59f1559 commit 22ea221
Show file tree
Hide file tree
Showing 31 changed files with 1,735 additions and 1,033 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/format-black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Format with black
on: [push, pull_request]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Format files using the black formatter
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: "."
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Formatted with black
2 changes: 1 addition & 1 deletion API/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
공공데이터포털 API를 이용한 데이터 수집을 위한 패키지입니다.
"""
"""
108 changes: 55 additions & 53 deletions API/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
from configurations.secrets import OpenDataPortalSecrets

BASE_DIR = os.path.join(os.path.dirname(__file__), os.pardir)
base_url = 'http://apis.data.go.kr/9760000/PofelcddInfoInqireService/getPofelcddRegistSttusInfoInqire'
base_url = "http://apis.data.go.kr/9760000/PofelcddInfoInqireService/getPofelcddRegistSttusInfoInqire"
page_no = 1
num_of_rows = 10000

parliamentVote = [20220601, 20230405]
sgCodes = input("Input the number of sgTypecode: ").split(',')
sgCodes = input("Input the number of sgTypecode: ").split(",")
data_list = []
for sgId in parliamentVote:
for code in sgCodes:
params = {
'serviceKey': OpenDataPortalSecrets.service_key,
'pageNo': str(page_no),
'numOfRows': str(num_of_rows),
'sgId': str(sgId),
'sgTypecode': str(code),
'sggName': '',
'sdName': '',
'jdName': ''
"serviceKey": OpenDataPortalSecrets.service_key,
"pageNo": str(page_no),
"numOfRows": str(num_of_rows),
"sgId": str(sgId),
"sgTypecode": str(code),
"sggName": "",
"sdName": "",
"jdName": "",
}

response = requests.get(base_url, params=params)
Expand All @@ -34,56 +34,58 @@
root = ET.fromstring(response.content)

for item in root.findall(".//item"):
sgId = item.find('sgId').text
sggName = item.find('sggName').text
sdName = item.find('sdName').text
wiwName = item.find('wiwName').text
giho = item.find('giho').text
jdName = item.find('jdName').text
name = item.find('name').text
hanjaName = item.find('hanjaName').text
gender = item.find('gender').text
birthday = item.find('birthday').text
age = item.find('age').text
addr = item.find('addr').text
jobId = item.find('jobId').text
job = item.find('job').text
eduId = item.find('eduId').text
edu = item.find('edu').text
career1 = item.find('career1').text
career2 = item.find('career2').text
status = item.find('status').text
sgId = item.find("sgId").text
sggName = item.find("sggName").text
sdName = item.find("sdName").text
wiwName = item.find("wiwName").text
giho = item.find("giho").text
jdName = item.find("jdName").text
name = item.find("name").text
hanjaName = item.find("hanjaName").text
gender = item.find("gender").text
birthday = item.find("birthday").text
age = item.find("age").text
addr = item.find("addr").text
jobId = item.find("jobId").text
job = item.find("job").text
eduId = item.find("eduId").text
edu = item.find("edu").text
career1 = item.find("career1").text
career2 = item.find("career2").text
status = item.find("status").text

data_list.append({
'sgId': sgId,
'sggName': sggName,
'sdName': sdName,
'wiwName': wiwName,
'giho': giho,
'jdName': jdName,
'name': name,
'hanjaName': hanjaName,
'gender': gender,
'birthday': birthday,
'age': age,
'addr': addr,
'jobId': jobId,
'job': job,
'eduId': eduId,
'edu': edu,
'career1': career1,
'career2': career2,
'status': status
})
data_list.append(
{
"sgId": sgId,
"sggName": sggName,
"sdName": sdName,
"wiwName": wiwName,
"giho": giho,
"jdName": jdName,
"name": name,
"hanjaName": hanjaName,
"gender": gender,
"birthday": birthday,
"age": age,
"addr": addr,
"jobId": jobId,
"job": job,
"eduId": eduId,
"edu": edu,
"career1": career1,
"career2": career2,
"status": status,
}
)

# Create a DataFrame from the collected data
df = pd.DataFrame(data_list)

# Save the DataFrame to an Excel file
directory_path = os.path.join(BASE_DIR, 'output')
directory_path = os.path.join(BASE_DIR, "output")
if not os.path.exists(directory_path):
os.makedirs(directory_path)
excel_file = '[후보][구시군의회의원].xlsx'
excel_file = "[후보][구시군의회의원].xlsx"
df.to_excel(os.path.join(directory_path, excel_file), index=False)

print(f'Data has been saved to {excel_file}')
print(f"Data has been saved to {excel_file}")
118 changes: 64 additions & 54 deletions API/elected.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@
from configurations.secrets import OpenDataPortalSecrets

BASE_DIR = os.path.join(os.path.dirname(__file__), os.pardir)
base_url = 'http://apis.data.go.kr/9760000/WinnerInfoInqireService2/getWinnerInfoInqire'
params ={'serviceKey' : OpenDataPortalSecrets.service_key,\
'pageNo' : '1', 'numOfRows' : '10', 'sgId' : '20230405', 'sgTypecode' : '2', 'sdName' : '전라북도', 'sggName' : '전주시을', 'jdName' : ''}
base_url = "http://apis.data.go.kr/9760000/WinnerInfoInqireService2/getWinnerInfoInqire"
params = {
"serviceKey": OpenDataPortalSecrets.service_key,
"pageNo": "1",
"numOfRows": "10",
"sgId": "20230405",
"sgTypecode": "2",
"sdName": "전라북도",
"sggName": "전주시을",
"jdName": "",
}
page_no = 1
num_of_rows = 10000

parliamentVote = [20200415, 20210407, 20220601, 20230405]
sgCodes = input("Input the number of sgTypecode: ").split(',')
sgCodes = input("Input the number of sgTypecode: ").split(",")
data_list = []
for sgId in parliamentVote:
for code in sgCodes:
params = {
'serviceKey': OpenDataPortalSecrets.service_key,
'pageNo': str(page_no),
'numOfRows': str(num_of_rows),
'sgId': str(sgId),
'sgTypecode': str(code),
'sggName': '',
'sdName': '',
'jdName': ''
"serviceKey": OpenDataPortalSecrets.service_key,
"pageNo": str(page_no),
"numOfRows": str(num_of_rows),
"sgId": str(sgId),
"sgTypecode": str(code),
"sggName": "",
"sdName": "",
"jdName": "",
}

response = requests.get(base_url, params=params)
Expand All @@ -36,56 +44,58 @@
root = ET.fromstring(response.content)

for item in root.findall(".//item"):
sgId = item.find('sgId').text
sggName = item.find('sggName').text
sdName = item.find('sdName').text
wiwName = item.find('wiwName').text
giho = item.find('giho').text
jdName = item.find('jdName').text
name = item.find('name').text
hanjaName = item.find('hanjaName').text
gender = item.find('gender').text
birthday = item.find('birthday').text
age = item.find('age').text
addr = item.find('addr').text
jobId = item.find('jobId').text
job = item.find('job').text
eduId = item.find('eduId').text
edu = item.find('edu').text
career1 = item.find('career1').text
career2 = item.find('career2').text
sgId = item.find("sgId").text
sggName = item.find("sggName").text
sdName = item.find("sdName").text
wiwName = item.find("wiwName").text
giho = item.find("giho").text
jdName = item.find("jdName").text
name = item.find("name").text
hanjaName = item.find("hanjaName").text
gender = item.find("gender").text
birthday = item.find("birthday").text
age = item.find("age").text
addr = item.find("addr").text
jobId = item.find("jobId").text
job = item.find("job").text
eduId = item.find("eduId").text
edu = item.find("edu").text
career1 = item.find("career1").text
career2 = item.find("career2").text
# status = item.find('status').text

data_list.append({
'sgId': sgId,
'sggName': sggName,
'sdName': sdName,
'wiwName': wiwName,
'giho': giho,
'jdName': jdName,
'name': name,
'hanjaName': hanjaName,
'gender': gender,
'birthday': birthday,
'age': age,
'addr': addr,
'jobId': jobId,
'job': job,
'eduId': eduId,
'edu': edu,
'career1': career1,
'career2': career2,
# 'status': status
})
data_list.append(
{
"sgId": sgId,
"sggName": sggName,
"sdName": sdName,
"wiwName": wiwName,
"giho": giho,
"jdName": jdName,
"name": name,
"hanjaName": hanjaName,
"gender": gender,
"birthday": birthday,
"age": age,
"addr": addr,
"jobId": jobId,
"job": job,
"eduId": eduId,
"edu": edu,
"career1": career1,
"career2": career2,
# 'status': status
}
)

# Create a DataFrame from the collected data
df = pd.DataFrame(data_list)

# Save the DataFrame to an Excel file
directory_path = os.path.join(BASE_DIR, 'output')
directory_path = os.path.join(BASE_DIR, "output")
if not os.path.exists(directory_path):
os.makedirs(directory_path)
excel_file = '[당선][구시군의회의원].xlsx'
excel_file = "[당선][구시군의회의원].xlsx"
df.to_excel(os.path.join(directory_path, excel_file), index=False)

print(f'Data has been saved to {excel_file}')
print(f"Data has been saved to {excel_file}")
31 changes: 19 additions & 12 deletions API/votecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,39 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--code', action='store_true', help='코드를 출력합니다.')
parser.add_argument("-c", "--code", action="store_true", help="코드를 출력합니다.")
args = parser.parse_args()
if args.code:
print("(0) 대표선거명 (1)대통령,(2)국회의원,(3)시도지사,(4)구시군장,(5)시도의원,\
(6)구시군의회의원, (7)국회의원비례대표,(8)광역의원비례대표,(9)기초의원비례대표,(10)교육의원,(11)교육감")
print(
"(0) 대표선거명 (1)대통령,(2)국회의원,(3)시도지사,(4)구시군장,(5)시도의원,\
(6)구시군의회의원, (7)국회의원비례대표,(8)광역의원비례대표,(9)기초의원비례대표,(10)교육의원,(11)교육감"
)
else:
print("sgTypecode를 입력하면 해당 sgTypecode와 일치하는 sgId 값을 출력합니다. 여러 개 입력하고 싶으면 ,로 구분해 주세요.")
print(
"sgTypecode를 입력하면 해당 sgTypecode와 일치하는 sgId 값을 출력합니다. 여러 개 입력하고 싶으면 ,로 구분해 주세요."
)

url = 'http://apis.data.go.kr/9760000/CommonCodeService/getCommonSgCodeList'
params ={'serviceKey' : OpenDataPortalSecrets.service_key,\
'pageNo' : '1', 'numOfRows' : '1000'}
url = "http://apis.data.go.kr/9760000/CommonCodeService/getCommonSgCodeList"
params = {
"serviceKey": OpenDataPortalSecrets.service_key,
"pageNo": "1",
"numOfRows": "1000",
}

response = requests.get(url, params=params)
xml_data = response.content.decode('utf-8')
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(','):
for item in root.findall(f'.//item[sgTypecode=\"{code}\"]'):
sgId_element = item.find('sgId')
for code in input("Input the number of sgTypecode: ").split(","):
for item in root.findall(f'.//item[sgTypecode="{code}"]'):
sgId_element = item.find("sgId")
if sgId_element is not None:
sgId = sgId_element.text
sgIds.add(sgId)

# Print the sgId values
for sgId in sorted(sgIds):
print(sgId)
print(sgId)
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
이 파일은 프로젝트 루트 폴더를 패키지로 인식하게 해주는 역할을 합니다.
"""
"""
2 changes: 1 addition & 1 deletion configurations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
스크립트 실행에 필요한 환경변수를 정의합니다.
환경변수는 프로젝트 루트 폴더에 .env 파일을 생성하여 불러올 수 있습니다.
"""
"""
Loading

0 comments on commit 22ea221

Please sign in to comment.