-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (44 loc) · 2.18 KB
/
main.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
from urllib.request import urlopen
from bs4 import BeautifulSoup
import time
import facebook
graph = facebook.GraphAPI(access_token=['EAAF4ktkd47sBAOBfBtiqt3b7FKTc1QGvlb7Fwwh2MjpqUjpFBoWwAP5ZC7Pp8H6Ws77yU8Y4Vt7T3RZCPyL1XEkXF3zdTapIwGs3eRrkXVoHVLggbIyJP3pTAFIbpqZB2hs1wq5p5exXyiaCNODrZAR3HZA33pRodqvpc5UD4g3D3HZBZAwV9kp'])
def post(text):
graph.put_object(parent_object='me', connection_name='feed',
message=text)
comp_idx=3189
corona_idx =120
while True:
corona_html = urlopen("https://www.knu.ac.kr/wbbs/wbbs/bbs/btin/list.action?bbs_cde=34&menu_idx=224")
cse_html = urlopen("http://cse.knu.ac.kr/06_sub/02_sub.html")
corona_info = BeautifulSoup(corona_html, "html.parser")
cse_info = BeautifulSoup(cse_html, "html.parser")
corona_num = corona_info.select("td.num")
corona_subject = corona_info.select("td.subject")
cse_subject = cse_info.find("table", {"class":"table"})
#print(cse_subject)
trs = cse_subject.find_all('tr')
for idx1, tr1 in enumerate(trs):
if(idx1>0):
tds = tr1.find_all('td')
if(len(tds)==5):
latest_comp_idx = int(tds[0].text.strip())
break
latest_cor_idx=int(corona_num[0].text)
#print("==============컴퓨터학부 공지사항==============")
#tr안에 td는 5개(번호, 제목, 글쓴이, 날짜, 조회수)
for idx, tr in enumerate(trs):
if(idx>0):
tds = tr.find_all('td')
if(len(tds)==5):
sequence = int(tds[0].text.strip())
if(sequence>comp_idx):
title = tds[1].text.strip().replace('\t', '').replace('\n', '').replace('\r', '')
post("컴퓨터학부 공지 : \n"+title+"\nhttp://cse.knu.ac.kr/06_sub/02_sub.html"+tds[1].a.get('href'))
#print("==============코로나19 공지사항==============")
for key1, key2 in zip(corona_num, corona_subject):
if(int(key1.text)>corona_idx):
post("코로나19 공지 : \n"+key2.text.strip()+"\nhttps://www.knu.ac.kr/wbbs/wbbs/bbs/btin/list.action?bbs_cde=34&menu_idx=224"+key2.a.get('href'))
comp_idx=latest_comp_idx
corona_idx=latest_cor_idx
time.sleep(100)