유지훈

Revert "Revert "Merge branch '2014104121' into 'master'""

This reverts commit 6072a09f
No preview for this file type
1 +from bs4 import BeautifulSoup
2 +from urllib.request import urlopen
3 +import openpyxl
4 +import datetime
5 +
6 +# coding = utf-8
7 +
8 +filename = "C://area_code.xlsx" # area_code.xlsx
9 +book = openpyxl.load_workbook(filename)
10 +
11 +sheet = book.worksheets[0]
12 +code = []
13 +
14 +for cell in sheet['E']:
15 + code.append(cell.value)
16 +
17 +area = input("읍/면/동을 입력(띄어쓰기 없이 입력 - 예:영통3동)\n")
18 +col = code.index(area)
19 +area_code_index = 'B' + str(col+1)
20 +area_code = sheet[area_code_index].value
21 +#print(area_code)
22 +
23 +now = datetime.datetime.now()
24 +nowDate = now.strftime('%Y%m%d') #20191201형태로 연월일 받음
25 +#print(nowDate)
26 +
27 +url = "http://newsky2.kma.go.kr/iros/RetrieveLifeIndexService3/getSensorytemLifeList?serviceKey=UwTMv516Y0zIgZCDqzdPtf1jmbv287%2BOn1kqxcZizw8%2Be5OV5UmIc09icqMqSpEMbHOiCWoPK%2BZVD%2Bjbc%2BwgBg%3D%3D&areaNo=" + area_code + "&time=" + nowDate + "03"
28 +
29 +result = urlopen(url)
30 +
31 +html = result.read()
32 +
33 +soup = BeautifulSoup(html, 'html.parser')
34 +
35 +contents = soup.find("date")
36 +hours = ["h3","h6","h9","h12","h15","h18","h21","h24"] # date의 시간으로부터 n시간 이후의 예측온도
37 +sens_temper = []
38 +# 2019120103: 19년 12월 1일 새벽 3시 기준이므로 리스트에는 6시, 9시, ..., 익일 3시까지의 예측 체감온도가 저장됨.
39 +#sens_temper[06시온도,09시온도,12시온도,15시온도,18시온도,21시온도,24시온도,익일03시온도]
40 +
41 +for i in range(0, len(hours)):
42 + temper = soup.find(hours[i])
43 + sens_temper.append(int(temper.text))
44 + if i < 2:
45 + print("0"+str(int(hours[i][1:])+3)+"시:", temper.text+"°C")
46 +
47 + elif i == 7:
48 + print("익일 03시:", temper.text+"°C")
49 + else:
50 + print(str(int(hours[i][1:])+3)+"시:", temper.text+"°C")
51 +
52 +if max(sens_temper) <= 5:
53 + if min(sens_temper) >= -5 and min(sens_temper) <=0:
54 + print("패딩, 겨울야상, 양털자켓, 폴라티, 니트, 기모바지")
55 + print("쌀쌀한 날씨입니다. 생각보다 추워요!")
56 + elif min(sens_temper) < -5:
57 + print("패딩, 겨울야상, 양털자켓, 폴라티, 니트, 기모바지")
58 + print("마스크, 목도리, 장갑을 착용하세요!")
59 + if min(sens_temper) < -10:
60 + print("외출을 자제하는 것이 좋겠습니다!")
61 + elif min(sens_temper) > 0:
62 + print("패딩, 겨울야상, 양털자켓, 폴라티, 니트, 기모바지, 스타킹")
63 + print("0도를 웃도는 날씨네요. 외투 안에는 가벼운 옷을 추천해요!")
64 +
65 +
66 +if max(sens_temper) >= 6 and max(sens_temper) <= 9:
67 + print("코트, 가죽자켓, 맨투맨, 티셔츠(사계절), 바지(사계절)")
68 + if min(sens_temper) < 3:
69 + print("일교차에 유의하세요! 추위에 약한 분들은 외투 하나 더 챙기세요!")
70 +
71 +elif max(sens_temper) >= 10 and max(sens_temper) <= 11:
72 + print("트렌치코트, 간절기 야상, 후드티, 여러겹 레이어드")
73 + if min(sens_temper) < 5:
74 + print("일교차에 유의하세요! 추위에 약한 분들은 외투 하나 더 챙기세요!")
75 +
76 +elif max(sens_temper) >= 12 and max(sens_temper) <= 16:
77 + print("자켓, 셔츠, 가디건, 후드(사계절)")
78 + if min(sens_temper) < 6:
79 + print("일교차에 유의하세요! 추위에 약한 분들은 외투 하나 더 챙기세요!")
80 +
81 +elif max(sens_temper) >= 17 and max(sens_temper) <= 19:
82 + print("가디건, 니트, 맨투맨, 후드티, 면바지, 슬랙스, 원피스")
83 + if min(sens_temper) < 9:
84 + print("일교차에 유의하세요! 얇은 외투 챙겨가세요!")
85 +
86 +elif max(sens_temper) >= 20 and max(sens_temper) <= 22:
87 + print("긴팔티, 후드티, 면바지, 슬랙스")
88 + if min(sens_temper) < 11:
89 + print("일교차에 유의하세요! 얇은 외투 챙겨가세요!")
90 +
91 +elif max(sens_temper) >= 23 and max(sens_temper) <= 26:
92 + print("반팔티, 얇은 셔츠, 얇은 긴팔티, 반바지, 면바지")
93 +
94 +