-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs.py
52 lines (47 loc) · 1.84 KB
/
cs.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
import requests, json
from bs4 import BeautifulSoup
from datetime import datetime
def get_cs_notice(row, logger):
_id, last_num = row['id'], row['last_num']
result = []
URL_list = ["http://cs.skku.edu/ajax/board/view/notice/", "http://cs.skku.edu/ajax/board/view/news/",
"http://cs.skku.edu/ajax/board/view/seminar/", "http://cs.skku.edu/ajax/board/view/recruit/" ]
category_list = ["notice", "news", "seminar", "recruit"]
count = 0
last_num = last_num + 1
while True:
URL = URL_list[count] + str(last_num)
response = requests.post(URL)
response.encoding = 'UTF-8'
if response.status_code != requests.codes.ok:
count = count + 1
if count == 4:
break
continue
jsonify_response = json.loads(response.text)
if jsonify_response['result']:
notice_json = json.loads(response.text)["post"]
soup = BeautifulSoup(notice_json['text'], 'html5lib')
img_src = ""
for img in soup.findAll('img'):
img_src = img_src + "http://cs.skku.edu" + img['src'] + "#"
img_src = img_src[:len(img_src)-1]
contents = soup.text
link = "http://cs.skku.edu/open/" + category_list[count] + "/view/" + str(notice_json['id'])
notice = {
'id': _id,
'title': notice_json['title'],
'last_num': notice_json['id'],
'contents': contents,
'link': link,
'img_src': img_src,
'type': row['type'],
'ntype': 'H'
}
result.append(notice)
count = 0
last_num = last_num + 1
else:
break
logger.info('get '+ str(len(result)) + ' new cs notice')
return result