-
Notifications
You must be signed in to change notification settings - Fork 0
/
pracflask.py
157 lines (145 loc) · 6.85 KB
/
pracflask.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
from bs4 import BeautifulSoup
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
def makeurl(utr):
title_list = []
link_list = []
ref1 = db.reference("제목")
ref2 = db.reference("링크")
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'}
if utr == "일반-학사":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=0&mode=list&searchKey=1&searchVal="
url2 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=1&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
html2 = requests.get(url2, headers=header)
soup2 = BeautifulSoup(html2.text, 'html.parser')
content2 = soup2.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
maketitle(content2, title_list)
makelink(content2, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"일반-학사": title_list})
ref2.update({"일반-학사": link_list})
elif utr == "병무-외부":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=7&mode=list&searchKey=1&searchVal="
url2 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=8&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
html2 = requests.get(url2, headers=header)
soup2 = BeautifulSoup(html2.text, 'html.parser')
content2 = soup2.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
maketitle(content2, title_list)
makelink(content2, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"병무-외부": title_list})
ref2.update({"병무-외부": link_list})
elif utr == "등록-장학":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=4&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"등록-장학": title_list})
ref2.update({"등록-장학": link_list})
elif utr == "입학-시설":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=5&mode=list&searchKey=1&searchVal="
url2 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=6&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
html2 = requests.get(url2, headers=header)
soup2 = BeautifulSoup(html2.text, 'html.parser')
content2 = soup2.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
maketitle(content2, title_list)
makelink(content2, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"입학-시설": title_list})
ref2.update({"입학-시설": link_list})
elif utr == "전체":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"전체": title_list})
ref2.update({"전체": link_list})
elif utr == "학생-봉사":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=2&mode=list&searchKey=1&searchVal="
url2 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=3&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
html2 = requests.get(url2, headers=header)
soup2 = BeautifulSoup(html2.text, 'html.parser')
content2 = soup2.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
maketitle(content2, title_list)
makelink(content2, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"학생-봉사": title_list})
ref2.update({"학생-봉사": link_list})
elif utr == "국제교류-국제학생":
url1 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=9&mode=list&searchKey=1&searchVal="
url2 = "https://www.kw.ac.kr/ko/life/notice.jsp?srCategoryId=10&mode=list&searchKey=1&searchVal="
html1 = requests.get(url1, headers=header)
soup1 = BeautifulSoup(html1.text, 'html.parser')
content1 = soup1.select('div.board-text > a')
html2 = requests.get(url2, headers=header)
soup2 = BeautifulSoup(html2.text, 'html.parser')
content2 = soup2.select('div.board-text > a')
maketitle(content1, title_list)
makelink(content1, link_list)
maketitle(content2, title_list)
makelink(content2, link_list)
if len(title_list) == 0:
title_list.append(0)
link_list.append(0)
ref1.update({"국제교류-국제학생": title_list})
ref2.update({"국제교류-국제학생": link_list})
def maketitle(parsing, title_list):
for title in parsing:
if "신규게시글" in title.text:
title = title.text
title = ''.join(title.split())
title_list.append(title.replace("신규게시글", "").replace("Attachment", ""))
def makelink(parsing, link_list):
for link in parsing:
if "신규게시글" in link.text:
link = link.get('href')
link_list.append("https://www.kw.ac.kr" + link)
#Firebase database 인증 및 앱 초기화
cred = credentials.Certificate('mykey.json')
firebase_admin.initialize_app(cred, {
'databaseURL' : 'https://kwnoti-fefb3.firebaseio.com/'
})
categorize = ["일반-학사", "병무-외부", "등록-장학", "입학-시설", "학생-봉사", "전체", "국제교류-국제학생"]
for utr in categorize:
makeurl(utr)