forked from AwayDay/heroku-flask-prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
109 lines (90 loc) · 2.84 KB
/
test.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
from flask import Flask, request, jsonify
import requests
from bs4 import BeautifulSoup
import datetime
import time
app = Flask(__name__)
url = 'https://www.kw.ac.kr/ko/life/notice.jsp'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
html = requests.get(url, headers=header)
soup = BeautifulSoup(html.text, 'html.parser')
title_list = []
link_list = []
link_lists = []
title_lists = []
titles = soup.select('div.board-text > a')
links = soup.select('div.board-text > a')
@app.route('/keyboard', '/')
def Keyboard():
dataSend = {
}
return jsonify(dataSend)
def title(j):
for title in titles:
title = title.text
title = ''.join(title.split())
title_list.append(title)
for i in range(10):
title_lists.append(title_list[i].replace("신규게시글", "").replace("Attachment", ""))
i = i + 1
return (title_lists[j])
def link(k):
for link in links:
link = link.get('href')
link_list.append(link)
for i in range(10):
link_lists.append("https://www.kw.ac.kr" + link_list[i])
i = i + 1
return (link_lists[k])
@app.route('/message', methods=['POST'])
def Message():
content = request.get_json()
content = content['userRequest']
content = content['utterance']
dataSend = {
"version": "2.0",
"template": {
"quickReplies": [
{
"label": "더 보기",
"action": "message"
}
],
"outputs": [
{
"carousel": {
"type": "basicCard",
"items": [
{
"title": title(0),
"buttons": [
{
"action": "webLink",
"label": "링크열기",
"webLinkUrl": link(0)
}
]
},
{
"title": title(1),
"buttons": [
{
"action": "webLink",
"label": "링크열기",
"webLinkUrl": link(1)
}
]
}
]
}
}
]
}
}
return jsonify(dataSend)
if __name__ == "__main__":
app.run
# while True:
# Message()
# time.sleep(10) #60초마다