'''
To-do
* logging
* 디테일 구현
'''
import requests
import xml.etree.ElementTree as ET
from dotenv import load_dotenv
import os
import pandas as pd
load_dotenv()
api_key = os.getenv('api_key')
city_list = pd.read_excel('./city.xlsx')
def get_population_info(city:str):
res = requests.get(f'<http://openapi.seoul.go.kr:8088/{api_key}/xml/citydata/1/1/{city}>')
root = ET.fromstring(res.content)
ppltn_info = root.find('CITYDATA').find('LIVE_PPLTN_STTS').find('LIVE_PPLTN_STTS')
status = ppltn_info.find('AREA_CONGEST_LVL').text
status_msg = ppltn_info.find('AREA_CONGEST_MSG').text
ppltn_min = int(ppltn_info.find('AREA_PPLTN_MIN').text)
ppltn_max = int(ppltn_info.find('AREA_PPLTN_MIN').text)
return status, status_msg, ppltn_min, ppltn_max
def insert_data():
...
if __name__ == '__main__':
for city in city_list:
ppltn_info = get_population_info(city)
insert_data(ppltn_info)