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

QiitaAPIにトレンドが見当たらないので泣いてたら

Last updated at Posted at 2018-02-19

2018/02/19

.jsonつけたらイケた
どしてもっと早く教えてくれないのん(´;ω;`)

追記

2018/03/22 9:00〜13:00頃
未ログインだと見れなくなってもうた(´;ω;`)

しょうがないからAPI経由で、過去x日でxストック以上された記事
https://qiita.com/search?q=stocks:>20+created:>2018-03-01
とかそんな感じのやつを取得して代用することにした

試してないけど多分こんな感じ

kuso_qiita.rb
require 'active_support'
require 'active_support/core_ext'
require 'qiita'

Time.zone = 'Asia/Tokyo'

def qiita_search_pages(qiita_client)
  search_deadline = 8.days.ago.strftime('%F')
  query = "stocks:>20 created:>#{search_deadline}"

  # 読んでも10ページまで
  (1..10).each_with_object([]) do |page, trend_pages|
    trend_page = qiita_search_page(qiita_client, page, query)
    trend_pages << trend_page

    break trend_pages if trend_page.next_page_url.blank?
  end
end

def qiita_search_page(qiita_client, page, query)
  qiita_client.list_items(page: page, per_page: 100, query: query)
end

qiita_client = Qiita::Client.new(access_token: ENV['QIITA_ACCESS_TOKEN'])

pages = qiita_search_pages(qiita_client)

#####
# 例えばuuid一覧を取得
#####

def qiita_pages_uuids(pages)
  pages.inject([]) do |uuids, page|
    uuids.concat(page.body.map { |item| item['id'] })
  end
end

uuids = qiita_pages_uuids(pages)

p uuids.map(&:presence).compact.uniq

追記2

2019/04/07
いつからそうだったのかは謎だけど、
トレンド情報をjsonで取得する事自体が出来なくなっている事を確認
@YumaInaura さんがコメントで教えてくれました

7
7
7

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