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-09 12:47:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8befe3f7f83bf854eb7216ae1a170154e0aaf8e2
8befe3f7
1 parent
2708a547
print out recipes that contain as many input ingredients as possible
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
I_to_D_chatbot/reply.js
I_to_D_chatbot/reply.js
View file @
8befe3f
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
''
const
TOKEN
=
'
zVAczqoJ+L9oykqhEj7HoP7f6Nyb+R3T1TntHXQhYihI+KIxH4SZDGpKu0jKsMXMHKBVXpmbybA+oaV8u/dfLppKe3NHXU9AdBVypy9NgfWiFPLlcwm3GdkVPAZGoS4nvOCXWDKUb+ixPKWjlbnChAdB04t89/1O/w1cDnyilFU=
'
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
...
...
@@ -26,28 +26,33 @@ app.post('/hook', function (req, res) {
var
db
=
mysql
.
createConnection
({
host
:
'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com'
,
user
:
'chatbot'
,
password
:
''
,
password
:
'
11111111
'
,
database
:
'chatbot'
,
port
:
'3306'
});
db
.
connect
();
var
max
=
0
;
db
.
query
(
'SELECT * FROM recipe'
,
function
(
error
,
results
,
fields
)
{
if
(
error
)
{
console
.
log
(
error
);
}
var
arr1
=
new
Array
();
var
arr2
=
new
Array
();
var
input_ingredients_list
=
message
.
text
.
split
(
" "
);
console
.
log
(
input_ingredients_list
);
for
(
var
i
=
0
;
i
<
results
.
length
;
i
++
)
{
var
ingredients_list
=
results
[
i
].
ingrediant
.
split
(
","
);
var
count
=
ingredients_list
.
filter
(
x
=>
input_ingredients_list
.
includes
(
x
)).
length
;
if
(
count
>
max
)
{
max
=
count
;
var
arr2
=
new
Array
();
}
if
(
count
===
input_ingredients_list
.
length
)
{
arr1
.
push
(
i
);
}
else
if
(
arr1
.
length
===
0
&&
count
!=
0
)
{
else
if
(
arr1
.
length
===
0
&&
count
!=
0
&&
count
===
max
)
{
arr2
.
push
(
i
);
}
}
...
...
Please
register
or
login
to post a comment