Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신승미
/
weatherClothing
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Seungmi
2020-12-10 22:15:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6b9bbd6ed3045ae5f8b31d76763e623c9d5ea59c
6b9bbd6e
1 parent
da2fe7fe
수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
14 deletions
weather_chat.py
weather_chat.py
View file @
6b9bbd6
...
...
@@ -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
(
current
weather
)):
if
current
weather
[
i
]
==
','
:
weather_endIndex
=
i
break
weather
=
find_
weather
[
0
:
weather_endIndex
]
weather
=
current
weather
[
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
)
...
...
Please
register
or
login
to post a comment