From 50d9febae21743b5d4b52731ec32859266961e1a Mon Sep 17 00:00:00 2001 From: Anton Lysenko Date: Tue, 25 Sep 2018 18:49:34 +0300 Subject: [PATCH] postInfo command added --- README.md | 6 ++++++ cli/postInfo.js | 11 +++++++++++ index.js | 2 +- lib/cli.js | 1 + package.json | 2 +- tools/postInfo.js | 19 +++++++++++++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 cli/postInfo.js create mode 100644 tools/postInfo.js diff --git a/README.md b/README.md index 962b6f7..b1b0ae6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ Optional params (with example) ``` --tags "one, second one"``` +### Post media file to blog + +````bash +tt postInfo -c path/to/keys.json -b blogName --id "post-id" +```` + ### Clean broken video posts tool Broken media posts cleaning tool. Cleans up (removes) video-posts with media pointing to 403 error returning URLs (by default). See available options below. diff --git a/cli/postInfo.js b/cli/postInfo.js new file mode 100644 index 0000000..cb50c38 --- /dev/null +++ b/cli/postInfo.js @@ -0,0 +1,11 @@ +module.exports = yargs => { + + yargs + .describe('b', 'Blog name from where the post') + .usage('Usage: $0 postInfo -c [file] -b [blog] --id ') + .option('id', { + describe: 'Tumblr post id', + demandOption: true, + type: 'string', + }); +} diff --git a/index.js b/index.js index 8e9b4fb..7b5e109 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const command = argv._[0]; const tool = require(`./tools/${command}`)(argv); // ugly as hell -if (command !== 'post') { +if (!['post', 'postInfo'].includes(command)) { const feed = require('./lib/feed')(tool.cli); feed.stream(tool.processor); } diff --git a/lib/cli.js b/lib/cli.js index ce07963..eb825ee 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -87,6 +87,7 @@ module.exports = { cli: require('yargs') .command('post', 'Create blog post', require('../cli/post')) + .command('postInfo', 'Get post info', require('../cli/postInfo')) .command('clean', 'Clean unavailable videos', yargs => { yargs diff --git a/package.json b/package.json index 70a688c..040f685 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tumblr-toolkit", - "version": "0.4.1", + "version": "0.5.0", "description": "Tumblr API-based toolkit for batch posts processing.", "main": "api.js", "dependencies": { diff --git a/tools/postInfo.js b/tools/postInfo.js new file mode 100644 index 0000000..c658ba1 --- /dev/null +++ b/tools/postInfo.js @@ -0,0 +1,19 @@ +const tumblrJs = require('tumblr.js'); + +module.exports = async (params) => { + const { id } = params; + + const tumblr = tumblrJs.createClient({ + credentials: params.credentials, + returnPromises: true, + }); + + try { + const result = await tumblr.blogPosts(params.blog, { id }); + console.log(result); + return result; + } catch (error) { + console.error(error); + return error; + } +}