Seungmi

수정

......@@ -6,27 +6,60 @@ from pprint import pprint
html = requests.get('https://search.naver.com/search.naver?query=날씨')
soup = BeautifulSoup(html.text, 'html.parser')
data1 = soup.find('div', {'class': 'weather_box'})
# 위치
address = data1.find('span', {'class': 'btn_select'}).text
weather_data = soup.find('div', {'class': 'weather_box'})
# 날씨
find_weather= data1.find('p', {'class': 'cast_txt'}).text
currentweather= weather_data.find('p', {'class': 'cast_txt'}).text
weather_endIndex = 0
for i in range(0,len(find_weather)):
if find_weather[i] == ',':
for i in range(0,len(currentweather)):
if currentweather[i] == ',':
weather_endIndex = i
break
weather = find_weather[0:weather_endIndex]
weather = currentweather[0:weather_endIndex]
# 온도
find_currenttemp = data1.find('span', {'class':'todaytemp'}).text
currentTemp = int(find_currenttemp)
currenttemp_data = weather_data.find('span', {'class':'todaytemp'}).text
currentTemp = int(currenttemp_data)
# 미세먼지
dust_data = weather_data.findAll('dd')
# 미세먼지, 초미세먼지, 오존지수 상태
dust_txt = dust_data[0].find('span', {'class':'num'}).text
dust = int(dust_txt[0:-3])
if dust > 150:
dust_status = "매우나쁨"
elif dust > 80:
dust_status = "나쁨"
elif dust > 30:
dust_status = "보통"
else:
dust_status = "좋음"
microdust_txt = dust_data[1].find('span', {'class':'num'}).text
microdust = int(microdust_txt[0:-3])
if microdust > 75:
microdust_status = "매우나쁨"
elif microdust > 35:
microdust_status = "나쁨"
elif microdust > 15:
microdust_status = "보통"
else:
microdust_status = "좋음"
ozone_txt = dust_data[2].find('span', {'class':'num'}).text
ozone = float(ozone_txt[0:-3])
if ozone > 0.151:
ozone_status = "매우나쁨"
elif ozone > 0.15:
ozone_status = "나쁨"
elif ozone > 0.03:
ozone_status = "보통"
else:
ozone_status = "좋음"
# 추천 옷차림새
if currentTemp >= 27:
......@@ -56,5 +89,9 @@ elif '눈' in weather:
else:
notice = "특이사항이 없습니다."
full = "현재 위치: "+address+'\n오늘의 온도: '+str(currentTemp)+'도'+'\n오늘의 날씨: '+weather+'\n추천 옷차림새: '+recDress+'\n특이사항: '+notice
print(full)
print('오늘의 온도: '+str(currentTemp)+'도'+
'\n오늘의 날씨: '+weather+'\n미세먼지: '+str(dust)+' '+dust_status+'\n초미세먼지: '+str(microdust)+' '+microdust_status+
'\n오존농도: '+str(ozone)+' '+ozone_status+'\n추천 옷차림새: '+recDress+'\n특이사항: '+notice)
......