Node.js
QiitaAPI
AngularJS

Qiita API を使って投稿の一覧を作成する

作成した私の投稿一覧のページ

qiita_jul2501.png

curl を使って ekzemplaro の投稿のページを取得

curl https://qiita.com/api/v2/users/ekzemplaro/items?per_page=100 > qiita_ekzemplaro.json

JSON のフォーマットを変換

qiita_read.js
#! /usr/bin/node
// ---------------------------------------------------------------
//  qiita_read.js
//
//                  Jul/25/2017
//
// ---------------------------------------------------------------
var fs = require("fs")
// ---------------------------------------------------------------
console.error ("*** 開始 ***")

const filename=process.argv[2]
const file_out=process.argv[3]

console.log (filename)

if (fs.existsSync(filename))
    {
    const json_str = fs.readFileSync (filename,'utf8')

    try
        {
        var array_out = Array()
        const array_aa = JSON.parse (json_str)

        console.log (array_aa.length)

        for (var it in array_aa)
            {
            var unit_aa = Object()
            unit_aa['title'] = array_aa[it].title
            unit_aa['url'] = array_aa[it].url
            const str_tmp = array_aa[it].updated_at.substring(0,16)
            unit_aa['updated_at'] = str_tmp.replace("T"," ")

            array_out.push(unit_aa)
            }

        const json_out = JSON.stringify(array_out)

        fs.writeFile (file_out,json_out,function (err)
        {
        if (err) {
            console.error ("Error on write: " + err)
            }
        else {
            fs.chmodSync (file_out,0666)
            console.log("File written.")
            console.error ("*** 終了 ***")
            }
        })
        }
    catch (error)
        {
        console.error ("*** error *** from JSON.parse ***")
        console.error (error)
        }
    }
else
    {
    console.error ("*** error *** " + filename + " doesn't exist. ***")
    }


console.error ("*** 終了 ***")
// ---------------------------------------------------------------

JSON の変換

./qiita_read.js qiita_ekzemplaro.json qiita_short.json

angular.js を使って、web で表示

<!DOCTYPE html>
<html ng-app="myApp" lang="ja">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<script src="/js/angular.min.js"></script>
<script src="qiita.js"></script>
<link rel="stylesheet" href="qiita.css">
<title>Qiita</title>
</head>
<body ng-controller="MainController">
<table>
<tr>
<th>title</th>
<th>updated_at</th>
</tr>
<tr ng-repeat="value in items">
<td><a href="{{value.url}}">
{{value.title}}</a></td>
<td>{{value.updated_at}}</td>
</tr>
</table>

<p />


<hr />
<a href="../">Return</a><p />
Jul/25/2017 AM 08:25<p />
</body>
</html>

参考ページ
Qiita API v2の仕様