diff --git a/config.json b/config.json index a17ba2b..cc75498 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "booru": "testbooru", - "tags": ["onodera_kosaki", "-underwear"], + "booru": "danbooru", + "tags": ["onodera_kosaki"], "rating": "safe" } diff --git a/src/helpers/API.js b/src/helpers/API.js index 0b5a3d7..3ef8b7b 100644 --- a/src/helpers/API.js +++ b/src/helpers/API.js @@ -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` + ); } ); }); diff --git a/src/public/assets/index.js b/src/public/assets/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/public/assets/main.css b/src/public/assets/main.css new file mode 100644 index 0000000..e69de29 diff --git a/src/public/index.html b/src/public/index.html new file mode 100644 index 0000000..e69de29