LoginSignup
0
0

More than 5 years have passed since last update.

はてなダイアリーの下書きをWSSE認証でダウンロード

Posted at

はてなダイアリーの下書きをエクスポートする方法がわからなかったので、纏めてダウンロードするツールを書いてダウンロードした。

WSSEとかクッソ懐しいな。。今はJWTとかJSON APIが全盛だけど、gRPCとかが流行ってJSONテクノロジが今のXMLテクノロジと同じように懐しいもの扱いされる時代が来るんだろうか。。

仕様

コード

ユーザ名、apitokenとページ数は手動で設定する必要がある。apiトークンは、"投稿用メールアドレス"の名前部分になる。

const MAXPAGE = 12;
const hatena_username = "mjt";
// Acquire key at https://www.hatena.ne.jp/{{USERNAME}}/config/mail/upload
const hatena_apitoken = "XXXXXXXXXX";
// See AtomPub API at http://developer.hatena.ne.jp/ja/documents/diary/apis/atom
// See WSSE API at http://developer.hatena.ne.jp/ja/documents/auth/apis/wsse

const wsse = require("wsse");
const rp = require("request-promise-native");
const fs = require("fs");

var token = wsse({username: hatena_username, password: hatena_apitoken});

var page = 1;

async function readpage(page){
    let options = {
        url: "http://d.hatena.ne.jp/" + hatena_username + "/atom/draft?page=" + page.toString(),
        method: "GET",
        headers: {
            "X-WSSE": token.getWSSEHeader()
        }
    };
    console.log(options.url);
    const res = await rp(options);
    return res;
}

function doread(page){
    readpage(page).then(content => {
        fs.writeFileSync("page" + page.toString() + ".xml", content, "utf-8");
        if(page != MAXPAGE){
            doread(page+1);
        }
    });
}

doread(1);

感想

誰か(正規の方法を)説明してくれよ! (ロンリーウェーイ)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0