Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오세헌
/
Ingredient-to-Dish-ChatBot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
전언석
2022-06-06 14:46:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7dd9c3276489cd53f4092bb2d7ba6f21d85bcae3
7dd9c327
1 parent
fc3f245a
edit reply.js
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
16 deletions
I_to_D_chatbot/reply.js
api받을수있는코드.js
recipes/Crawling_Script.py
I_to_D_chatbot/reply.js
View file @
7dd9c32
...
...
@@ -21,16 +21,8 @@ app.post('/hook', function (req, res) {
// request log
console
.
log
(
'======================'
,
new
Date
(),
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
var
incredients_list
=
message
.
text
.
split
(
" "
);
function
findingredients
(
item
)
{
return
item
===
"김치"
;
}
// mwsql
// mysql -u chatbot -p -h chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com
var
mysql
=
require
(
'mysql'
);
var
db
=
mysql
.
createConnection
({
host
:
'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com'
,
...
...
@@ -60,11 +52,11 @@ app.post('/hook', function (req, res) {
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`
${
results
[
i
].
menu
}
`
"text"
:
`
메뉴는 "
${
results
[
i
].
menu
}
" 입니다.
`
},
{
"type"
:
"text"
,
"text"
:
`
${
results
[
i
].
recipe
}
`
"text"
:
`
레시피\n
${
results
[
i
].
recipe
}
`
}
]
}
...
...
@@ -91,5 +83,4 @@ try {
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
}
\ No newline at end of file
...
...
api받을수있는코드.js
View file @
7dd9c32
// var xhr = new XMLHttpRequest();
// var url = 'http://apis.data.go.kr/1390802/AgriFood/FdCkry/getKoreanFoodFdCkryList'; /*URL*/
// var queryParams = '?' + encodeURIComponent('serviceKey') + '='+'R7bFhjvvAMmxJxzcrL8NWkYHVa227zfpwvpwgXxcixNdMY0EbdbsbCboj3zXEsXniKNHyqu2dEllJCRk1LsdxA%3D%3D'; /*Service Key*/
// queryParams += '&' + encodeURIComponent('service_Type') + '=' + encodeURIComponent('xml'); /**/
// queryParams += '&' + encodeURIComponent('Page_No') + '=' + encodeURIComponent('1'); /**/
// queryParams += '&' + encodeURIComponent('Page_Size') + '=' + encodeURIComponent('20'); /**/
// queryParams += '&' + encodeURIComponent('food_Name') + '=' + encodeURIComponent('밥'); /**/
// queryParams += '&' + encodeURIComponent('ckry_Name') + '=' + encodeURIComponent('조리'); /**/
// xhr.open('GET', url + queryParams);
// xhr.onreadystatechange = function () {
// if (this.readyState == 4) {
// alert('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText);
// }
// };
// xhr.send('');
var
XMLHttpRequest
=
require
(
'xhr2'
);
var
xhr
=
new
XMLHttpRequest
();
var
url
=
'http://apis.data.go.kr/1390802/AgriFood/FdCkry/getKoreanFoodFdCkryList'
;
/*URL*/
var
queryParams
=
'?'
+
encodeURIComponent
(
'serviceKey'
)
+
'='
+
'R7bFhjvvAMmxJxzcrL8NWkYHVa227zfpwvpwgXxcixNdMY0EbdbsbCboj3zXEsXniKNHyqu2dEllJCRk1LsdxA%3D%3D'
;
/*Service Key*/
...
...
@@ -9,7 +27,11 @@ queryParams += '&' + encodeURIComponent('ckry_Name') + '=' + encodeURIComponent(
xhr
.
open
(
'GET'
,
url
+
queryParams
);
xhr
.
onreadystatechange
=
function
()
{
if
(
this
.
readyState
==
4
)
{
alert
(
'Status: '
+
this
.
status
+
'nHeaders: '
+
JSON
.
stringify
(
this
.
getAllResponseHeaders
())
+
'nBody: '
+
this
.
responseText
);
//console.log('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText);
//console.log(this.responseText);
console
.
log
(
this
.
responseText
);
console
.
log
(
"hehe\n"
);
console
.
log
(
queryParams
);
}
};
...
...
recipes/Crawling_Script.py
View file @
7dd9c32
...
...
@@ -3,14 +3,14 @@ import requests
from
bs4
import
BeautifulSoup
import
pymysql
#pip3 install requests, pip3 install pymy
a
ql, pip3 install beautifulsoup4를 하고 진행, pip3대신 pip 사용가능
#pip3 install requests, pip3 install pymy
s
ql, pip3 install beautifulsoup4를 하고 진행, pip3대신 pip 사용가능
#사이트가 크롤링을 공격으로 인식하는 것을 방지하기 위해 중간중간에 sleep함수를 사용
conn
=
pymysql
.
connect
(
host
=
"localhost"
,
user
=
"root"
,
password
=
'abcde12345abcde'
,
db
=
'db_recipe'
,
charset
=
'utf8'
)
curs
=
conn
.
cursor
(
pymysql
.
cursors
.
DictCursor
)
for
pagenum
in
range
(
1
,
35
):
#크롤링 할 상위 페이지 개수. 약 40개정도의 레시피 링크가 한 페이지에 이어져 있음
for
pagenum
in
range
(
1
,
2
):
#크롤링 할 상위 페이지 개수. 약 40개정도의 레시피 링크가 한 페이지에 이어져 있음
print
(
pagenum
)
page
=
requests
.
get
(
'https://www.10000recipe.com/recipe/list.html?order=reco&page='
+
str
(
pagenum
))
...
...
Please
register
or
login
to post a comment