Working api call - it only took an hour hehe haha
This commit is contained in:
parent
c25b8acd03
commit
79d8c9f74e
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"booru": "testbooru",
|
||||
"tags": ["onodera_kosaki", "-underwear"],
|
||||
"rating": "safe"
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
const request = require("request");
|
||||
const parseConfig = require("./config")
|
||||
|
||||
function search() {
|
||||
let configFile = "./config.json";
|
||||
parseConfig.readConfig(configFile, (err, config)=>{
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
request(
|
||||
`https://${config.booru}.donmai.us/posts/6.json`,
|
||||
{ json: true },
|
||||
(err, res, body) => {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
|
||||
console.log(body.id);
|
||||
console.log(body.created_at);
|
||||
console.log(body.rating);
|
||||
console.log(body.large_file_url);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { search };
|
|
@ -0,0 +1,18 @@
|
|||
const fs = require("fs");
|
||||
|
||||
|
||||
function readConfig(configPath, callBack) {
|
||||
fs.readFile(configPath, (err, configData) =>{
|
||||
if (err){
|
||||
return callBack && callBack(err);
|
||||
}
|
||||
try {
|
||||
const configObject = JSON.parse(configData);
|
||||
return callBack && callBack(null, configObject);
|
||||
} catch (err) {
|
||||
return callBack && callBack(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { readConfig };
|
13
src/index.js
13
src/index.js
|
@ -1,10 +1,7 @@
|
|||
const request = require('request');
|
||||
const search = require("./helpers/API")
|
||||
|
||||
async function main() {
|
||||
search.search();
|
||||
}
|
||||
|
||||
request('https://testbooru.donmai.us/posts/6.json', { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log(err); }
|
||||
console.log(body.id);
|
||||
console.log(body.created_at);
|
||||
console.log(body.rating);
|
||||
console.log(body.large_file_url)
|
||||
});
|
||||
main();
|
Loading…
Reference in New Issue