8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Groovy】特定ユーザーのQiitaの記事を全てダウンロードする【小人さんスクリプト】

Posted at

任意のユーザーのQiitaの全投稿をマークダウン(.md)形式で保存するスクリプトです。

2015年12月17日現在、QiitaのAPIは

利用制限
認証している状態ではユーザごとに1時間に1000回まで、認証していない状態ではIPアドレスごとに1時間に60回までリクエストを受け付けます。

という制限が有ります。

本投稿のコードは、IPアドレスごとに1時間60回という制限がありますので、その点に注意してください。

import groovy.json.*

def userId = "SOMEONE_ID" // 誰かのQiita IDを入れてください
def pagePerCount = 20

def userUrlString = "http://qiita.com/api/v2/users/${userId}"
def userResponseString = new URL(userUrlString).text
def userJson = new JsonSlurper().parseText (userResponseString)
def itemsCount = userJson.items_count
def pageCount = (int) Math.ceil(itemsCount / pagePerCount)

pageCount.times{ index ->
    def pageNumber = index + 1;

    def urlString = "http://qiita.com/api/v2/users/${userId}/items?page=${pageNumber}&per_page=${pagePerCount}"
    def responseString = new URL(urlString).text
    def response = new JsonSlurper().parseText (responseString)

    response.each { article ->
        def body = article.body
        def title = article.title
        new File("${title}.md").text = body
    }
}
8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?