Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김민욱
/
Slack Jokebot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
1
Network
Create a new issue
Commits
Issue Boards
Authored by
김연준
2019-05-25 17:53:07 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5d4074a6ad3db461a93b5c2d05bdf9aa0714b85d
5d4074a6
1 parent
9ea1990c
Deleting test files in master branch
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
67 deletions
test.js
test2.js
test.js
deleted
100644 → 0
View file @
9ea1990
//
const
joke
=
require
(
'./jokes/jokes.json'
);
const
MongoClient
=
require
(
'mongodb'
).
MongoClient
;
MongoClient
.
connect
(
'mongodb://localhost:27017'
,
function
(
err
,
client
){
if
(
err
)
throw
err
;
var
db
=
client
.
db
(
'jokeapi'
);
question
=
[];
punchline
=
[];
count
=
0
;
json_max
=
376
;
random
=
function
getRandomArbitrary
()
{
return
Math
.
random
()
*
(
376
-
1
)
+
1
;
}
for
(
var
i
=
1
;
i
<
json_max
+
1
;
i
++
){
result
=
db
.
collection
(
'jokes'
).
findOne
({
id
:
i
,
type
:
"programming"
});
if
(
result
===
null
)
return
;
else
if
(
result
)
{
++
count
;
question
.
push
(
result
.
setup
);
punchline
.
push
(
result
.
punchline
);
// var n = result.count(result);
// var r = Math.floor(Math.random() * n);
// var randomElement = result.find().limit(1).skip(r);
// var question = randomElement.setup;
// var joke = randomElement.punchline;
// console.log(question);
// console.log(joke);
// console.log(question);
// console.log(punchline);
//console.log(question);
}
}
client
.
close
();
console
.
log
(
question
);
});
test2.js
deleted
100644 → 0
View file @
9ea1990
const
MongoClient
=
require
(
'mongodb'
).
MongoClient
;
//Get Random Joke
MongoClient
.
connect
(
'mongodb://localhost:27017'
,
function
(
err
,
client
){
if
(
err
)
throw
err
;
var
db
=
client
.
db
(
'jokeapi'
);
json_max
=
376
;
function
getRandomInt
()
{
min
=
Math
.
ceil
(
1
);
max
=
Math
.
floor
(
376
);
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
))
+
min
;
}
random
=
getRandomInt
();
console
.
log
(
random
);
result
=
db
.
collection
(
'jokes'
).
findOne
({
id
:
random
});
user
=
result
;
user
.
then
(
function
(
total
){
console
.
log
(
total
.
setup
);
console
.
log
(
total
.
setup
);
})
client
.
close
();
})
Please
register
or
login
to post a comment