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 17:40:59 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
e0b34a50025f117c2be4b7627a60d077d1615ac9
e0b34a50
2 parents
88426ba4
3e1f275f
Merge branch 'reply' into 'master'
Reply See merge request
!5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
38 deletions
I_to_D_chatbot/reply.js
api받을수있는코드.js
recipes/Crawling_Script.py
I_to_D_chatbot/reply.js
View file @
e0b34a5
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'
zVAczqoJ+L9oykqhEj7HoP7f6Nyb+R3T1TntHXQhYihI+KIxH4SZDGpKu0jKsMXMHKBVXpmbybA+oaV8u/dfLppKe3NHXU9AdBVypy9NgfWiFPLlcwm3GdkVPAZGoS4nvOCXWDKUb+ixPKWjlbnChAdB04t89/1O/w1cDnyilFU=
'
const
TOKEN
=
''
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
...
...
@@ -21,21 +21,12 @@ 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'
,
user
:
'chatbot'
,
password
:
'
11111111
'
,
password
:
''
,
database
:
'chatbot'
,
port
:
'3306'
});
...
...
@@ -46,32 +37,63 @@ app.post('/hook', function (req, res) {
if
(
error
)
{
console
.
log
(
error
);
}
for
(
var
i
=
0
;
i
<
results
.
length
;
i
++
)
if
(
results
[
i
].
ingredients
===
message
.
text
)
{
console
.
log
(
`메뉴 :
${
results
[
i
].
menu
}
, 레시피 :
${
results
[
i
].
recipe
}
`
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`
${
results
[
i
].
menu
}
`
},
{
"type"
:
"text"
,
"text"
:
`
${
results
[
i
].
recipe
}
`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
var
arr
=
new
Array
();
var
input_ingredients_list
=
message
.
text
.
split
(
" "
);
for
(
var
i
=
0
;
i
<
results
.
length
;
i
++
)
{
var
ingredients_list
=
results
[
i
].
ingredients
.
split
(
", "
);
if
(
ingredients_list
.
filter
(
x
=>
input_ingredients_list
.
includes
(
x
)).
length
===
input_ingredients_list
.
length
)
{
arr
.
push
(
i
);
}
}
if
(
arr
.
length
!=
0
)
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
arr
.
length
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`메뉴는 "
${
results
[
num
].
menu
}
" 입니다.`
},
{
"type"
:
"text"
,
"text"
:
`필요한 재료는\n
${
results
[
num
].
ingredients
}
입니다.`
},
{
"type"
:
"text"
,
"text"
:
`레시피\n
${
results
[
num
].
recipe
}
`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
else
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`재료를 다시 입력해주세요.`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
db
.
end
();
...
...
api받을수있는코드.js
View file @
e0b34a5
// 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 @
e0b34a5
...
...
@@ -10,7 +10,7 @@ import pymysql
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