1
1

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.

Qiitaの自分の投稿の直近100件から、特定のタグを含む投稿を抽出してMarkdownとして整形するスクリプト

Last updated at Posted at 2014-01-11

以下の様なリンク集を作るスクリプトです

2013-12-27 [Go言語: 単体テストの始め方!Gospelを使ってBDDをやってみよう](http://qiita.com/suin/items/71f28f06e7a49414cc93)
2014-01-06 [Go言語:単体テストを複数のパッケージに対して実行する](http://qiita.com/suin/items/850b39625c92437d2362)
2014-01-06 [[教えて]Go言語:なぜインターフェイスはポインタにできない?](http://qiita.com/suin/items/68ed7020d21dca047a73)
2014-01-07 [Go言語:変数が関数かどうかを返す関数](http://qiita.com/suin/items/468108496cd0dc002f64)
2014-01-07 [Go言語:メソッドの引数の型を調べる方法](http://qiita.com/suin/items/ec2070fde6700ffc4a7f)
2014-01-08 [Go言語:自分のライブラリをGitHubで公開する方法+drone.ioで継続的インテグレーション](http://qiita.com/suin/items/1237f210ef9e81b6475d)
2014-01-10 [Go言語:Riakに書き込む](http://qiita.com/suin/items/942773fd059272825eb8)
2014-01-11 [動的言語だけやってた僕が、38日間Go言語を書いて学んだこと](http://qiita.com/suin/items/22662f43b6a6e8728798)

<?php

$tag = 'go'; // 探すタグ

$filename = 'https://qiita.com/api/v1/users/suin/items?per_page=100';

$contents = file_get_contents($filename);

$items = json_decode($contents, 1);

$items = array_filter($items, function (array $item) use ($tag) {
	foreach ($item['tags'] as $_tag) {
		if (strtolower($_tag['name']) == $tag) {
			return true;
		}
	}
	
	return false;
});

$items = array_map(function (array $item) {
	return [
		'url' => $item['url'],
		'title' => $item['title'],
		'created_at' => $item['created_at'],
	];
}, $items);

usort($items, function ($item1, $item2) {
	$created1 = new DateTime($item1['created_at']);
	$created2 = new DateTime($item2['created_at']);
	
	return ($created1 >= $created2) ? 1 : 0;
});

$markdown = '';

foreach ($items as $item) {
	$date = new DateTime($item['created_at']);
	$markdown .= sprintf('%s [%s](%s)', $date->format('Y-m-d'), $item['title'], $item['url']). PHP_EOL;
}


echo $markdown;

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?