Skip to content

Commit 5460569

Browse files
committed
Sort articles by stocked count 🍣
1 parent 778b8b7 commit 5460569

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

commands/search.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# encoding: utf-8
2+
require 'time'
23

34
QUERY = ARGV[0].to_s.strip
45

56
require_relative "../lib/qiita"
67

78
data = Qiita::API.search(QUERY)
9+
data.sort! {|a, b| b['stock_count'] <=> a['stock_count'] }
810

911
results = []
1012
data.each do |q|
1113
arg = q['url']
12-
subtitle = "Stocks: " + q['stock_count'].to_s + " LGTM:" + q['lgtm_count'].to_s + " Comments:" + q['comment_count'].to_s + " Create At:" + q['created_at']
14+
subtitle = q['stock_count'].to_s + " Stocks, " + q['comment_count'].to_s + " Comments, " + Time.parse(q['created_at']).strftime("%Y/%m/%d %H:%M:%S") + " Created"
1315

1416
item = {
15-
:uid => q['id'],
17+
:uid => nil,
1618
:arg => arg,
1719
:title => q['title'],
1820
:subtitle => subtitle,

commands/stocks.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
require 'time'
23

34
QUERY = ARGV[0].to_s.strip
45

@@ -16,13 +17,14 @@
1617
end
1718

1819
data = Qiita::API.search(QUERY, :token => config.token, :stocked => 1)
20+
data.sort! {|a, b| b['stock_count'] <=> a['stock_count'] }
1921

2022
results = []
2123
data.each do |q|
22-
subtitle = "Stocks: " + q['stock_count'].to_s + " LGTM:" + q['lgtm_count'].to_s + " Comments:" + q['comment_count'].to_s + " Create At:" + q['created_at']
24+
subtitle = q['stock_count'].to_s + " Stocks, " + q['comment_count'].to_s + " Comments, " + Time.parse(q['created_at']).strftime("%Y/%m/%d %H:%M:%S") + " Created"
2325

2426
item = {
25-
:uid => q['id'],
27+
:uid => nil,
2628
:arg => q['url'],
2729
:title => q['title'],
2830
:subtitle => subtitle,

0 commit comments

Comments
 (0)