-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdsc_ewha_project_.py
99 lines (80 loc) · 2.88 KB
/
gdsc_ewha_project_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-
"""GDSC EWHA project_.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1RiQQH8DXJDvOsJgvyuA9zCedj3_nO6ZM
"""
#드라이브 연동
from google.colab import drive
drive.mount('/content/drive')
import datetime
import urllib
from bs4 import BeautifulSoup
import urllib.request as req
now = datetime.datetime.now()
nowDate = now.strftime('%Y년 %m월 %d일 %H시 %M분 입니다.')
print("\n Python Weather Crawling 2022 Revise\n ")
print(' Current Datetime, ' + nowDate)
print(' 오늘의 날씨 정보입니다.\n')
# 기상청 데이터
url = "http://www.weather.go.kr/weather/forecast/mid-term-rss3.jsp"
res = req.urlopen(url)
# res = req.urlopen("http://www.weather.go.kr/weather/forecast/mid-term-rss3.jsp")
soup = BeautifulSoup(res, "html.parser")
title = soup.find("title").string
weather_info = soup.find("wf").string
print(title)
#print(weather_info)
# print(weather_info.replace("<br />","\n "),sep='\n')
import ssl
# Phase1 Seoul Weather Crawling
context = ssl._create_unverified_context()
webpage = urllib.request.urlopen('https://search.naver.com/search.naver?sm=top_hty&fbm=0&ie=utf8&query=%EC%84%9C%EC%9A%B8%EB%82%A0%EC%94%A8',context=context)
soup = BeautifulSoup(webpage, 'html.parser')
temps = soup.find('div','temperature_text')
summary = soup.find('p','summary')
#print(temps)
# print(summary)
print(summary.text.strip())
print("*"*30)
#print(temps.text.strip())
#weather = temps.text.strip()[5:]
weather = 29
print('현재 온도는 ', weather, '입니다.')
#weather_int = int(temps.text.strip()[5:-3])
weather_int = 29
#기온별 옷차림
_28 = [28, '민소매', '반팔', '반바지','린넨 셔츠']
_23 = [23, '반팔', '얇은 셔츠', '반바지']
_20 = [20, '블라우스', '긴팔 티', '면바지', '슬랙스']
_17 = [17, '가디건', '니트', '맨투맨', '후드', '긴 바지']
_12 = [12, '자켓', '가디건']
_9 = [9, '트렌치 코트', '야상', '점퍼', '기모바지']
_5 = [5, '울 코트', '히트텍', '가죽 옷']
_4 = [4, '패딩', '두꺼운 코트']
weather_clothes = [_28, _23, _20, _17, _12, _9, _5, _4]
def temp_clothes(w):
for i in range(len(weather_clothes)):
if w > weather_clothes[i][0]:
result = weather_clothes[i]
break
else:
result = weather_clothes[-1]
return result
clothes = temp_clothes(weather_int)
print('현재 온도',weather,'에 알맞는 옷 추천: ', clothes[1:])
print('*'*30)
#이미지 불러오기
import cv2
from google.colab.patches import cv2_imshow
print('현재 기온에 맞는 추천 코디입니다.\n')
n = 1
img_path = '/content/drive/MyDrive/Colab Notebooks/GDSC/image/'
for i in range(len(clothes)-1):
print(n,clothes[n])
img_path = '/content/drive/MyDrive/Colab Notebooks/GDSC/image/'
img_path = img_path + clothes[n] + '/1.jpg'
#print(img_path)
img = cv2.imread(img_path)
cv2_imshow(img)
n +=1