Showing
1 changed file
with
51 additions
and
14 deletions
... | @@ -6,27 +6,60 @@ from pprint import pprint | ... | @@ -6,27 +6,60 @@ from pprint import pprint |
6 | html = requests.get('https://search.naver.com/search.naver?query=날씨') | 6 | html = requests.get('https://search.naver.com/search.naver?query=날씨') |
7 | soup = BeautifulSoup(html.text, 'html.parser') | 7 | soup = BeautifulSoup(html.text, 'html.parser') |
8 | 8 | ||
9 | -data1 = soup.find('div', {'class': 'weather_box'}) | 9 | +weather_data = soup.find('div', {'class': 'weather_box'}) |
10 | - | ||
11 | -# 위치 | ||
12 | -address = data1.find('span', {'class': 'btn_select'}).text | ||
13 | - | ||
14 | 10 | ||
15 | # 날씨 | 11 | # 날씨 |
16 | -find_weather= data1.find('p', {'class': 'cast_txt'}).text | 12 | +currentweather= weather_data.find('p', {'class': 'cast_txt'}).text |
17 | - | ||
18 | weather_endIndex = 0 | 13 | weather_endIndex = 0 |
19 | 14 | ||
20 | -for i in range(0,len(find_weather)): | 15 | +for i in range(0,len(currentweather)): |
21 | - if find_weather[i] == ',': | 16 | + if currentweather[i] == ',': |
22 | weather_endIndex = i | 17 | weather_endIndex = i |
23 | break | 18 | break |
24 | 19 | ||
25 | -weather = find_weather[0:weather_endIndex] | 20 | +weather = currentweather[0:weather_endIndex] |
26 | 21 | ||
27 | # 온도 | 22 | # 온도 |
28 | -find_currenttemp = data1.find('span', {'class':'todaytemp'}).text | 23 | +currenttemp_data = weather_data.find('span', {'class':'todaytemp'}).text |
29 | -currentTemp = int(find_currenttemp) | 24 | +currentTemp = int(currenttemp_data) |
25 | + | ||
26 | +# 미세먼지 | ||
27 | +dust_data = weather_data.findAll('dd') | ||
28 | + | ||
29 | +# 미세먼지, 초미세먼지, 오존지수 상태 | ||
30 | +dust_txt = dust_data[0].find('span', {'class':'num'}).text | ||
31 | +dust = int(dust_txt[0:-3]) | ||
32 | + | ||
33 | +if dust > 150: | ||
34 | + dust_status = "매우나쁨" | ||
35 | +elif dust > 80: | ||
36 | + dust_status = "나쁨" | ||
37 | +elif dust > 30: | ||
38 | + dust_status = "보통" | ||
39 | +else: | ||
40 | + dust_status = "좋음" | ||
41 | + | ||
42 | +microdust_txt = dust_data[1].find('span', {'class':'num'}).text | ||
43 | +microdust = int(microdust_txt[0:-3]) | ||
44 | +if microdust > 75: | ||
45 | + microdust_status = "매우나쁨" | ||
46 | +elif microdust > 35: | ||
47 | + microdust_status = "나쁨" | ||
48 | +elif microdust > 15: | ||
49 | + microdust_status = "보통" | ||
50 | +else: | ||
51 | + microdust_status = "좋음" | ||
52 | + | ||
53 | +ozone_txt = dust_data[2].find('span', {'class':'num'}).text | ||
54 | +ozone = float(ozone_txt[0:-3]) | ||
55 | +if ozone > 0.151: | ||
56 | + ozone_status = "매우나쁨" | ||
57 | +elif ozone > 0.15: | ||
58 | + ozone_status = "나쁨" | ||
59 | +elif ozone > 0.03: | ||
60 | + ozone_status = "보통" | ||
61 | +else: | ||
62 | + ozone_status = "좋음" | ||
30 | 63 | ||
31 | # 추천 옷차림새 | 64 | # 추천 옷차림새 |
32 | if currentTemp >= 27: | 65 | if currentTemp >= 27: |
... | @@ -56,5 +89,9 @@ elif '눈' in weather: | ... | @@ -56,5 +89,9 @@ elif '눈' in weather: |
56 | else: | 89 | else: |
57 | notice = "특이사항이 없습니다." | 90 | notice = "특이사항이 없습니다." |
58 | 91 | ||
59 | -full = "현재 위치: "+address+'\n오늘의 온도: '+str(currentTemp)+'도'+'\n오늘의 날씨: '+weather+'\n추천 옷차림새: '+recDress+'\n특이사항: '+notice | 92 | + |
60 | -print(full) | 93 | +print('오늘의 온도: '+str(currentTemp)+'도'+ |
94 | +'\n오늘의 날씨: '+weather+'\n미세먼지: '+str(dust)+' '+dust_status+'\n초미세먼지: '+str(microdust)+' '+microdust_status+ | ||
95 | +'\n오존농도: '+str(ozone)+' '+ozone_status+'\n추천 옷차림새: '+recDress+'\n특이사항: '+notice) | ||
96 | + | ||
97 | + | ... | ... |
-
Please register or login to post a comment