1
0
Fork 0

Working api call - it only took an hour hehe haha

This commit is contained in:
grumbulon 2022-04-02 19:57:42 -04:00
parent c25b8acd03
commit 79d8c9f74e
4 changed files with 56 additions and 8 deletions

5
config.json Normal file
View File

@ -0,0 +1,5 @@
{
"booru": "testbooru",
"tags": ["onodera_kosaki", "-underwear"],
"rating": "safe"
}

28
src/helpers/API.js Normal file
View File

@ -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 };

18
src/helpers/config.js Normal file
View File

@ -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 };

View File

@ -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();