1
0
Fork 0

added functions to get proper post IDs at rand from danbooru-like APIs. Added download function. Other minor cleanup

This commit is contained in:
grumbulon 2022-04-02 21:20:19 -04:00
parent a4b90d3ed1
commit 8129565180
5 changed files with 31 additions and 7 deletions

View File

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

View File

@ -1,24 +1,48 @@
const { post, get } = require("request");
const request = require("request");
const parseConfig = require("./config");
const downloadFromBooru = require("./download");
let configFile = "./config.json";
function search() {
let configFile = "./config.json";
parseConfig.readConfig(configFile, (err, config) => {
if (err) {
console.log(err);
return;
}
//Get list of posts for the tag(s)
request(
`https://${config.booru}.donmai.us/posts.json?tags=${config.tags}&z=1`,
{ json: true },
(err, res, body) => {
if (err) {
return console.log(err);
}
const randPost = Math.floor(Math.random() * body.length);
const postID = body[randPost].id;
getPost(postID);
}
);
});
}
function getPost(postID) {
parseConfig.readConfig(configFile, (err, config) => {
if (err) {
console.log(err);
return;
}
request(
`https://${config.booru}.donmai.us/posts/6.json`,
`https://${config.booru}.donmai.us/posts/${postID}.json`,
{ json: true },
(err, res, body) => {
if (err) {
return console.log(err);
}
console.log(body)
downloadFromBooru.downloadFromBooru(body.large_file_url, `./img/${body.id}.png`)
downloadFromBooru.downloadFromBooru(
body.large_file_url,
`./img/${body.id}.png`
);
}
);
});

View File

View File

0
src/public/index.html Normal file
View File