Add script for generating link list
1 files changed, 75 insertions(+), 0 deletions(-) A bin/links
A bin/links => bin/links +75 -0
@@ 0,0 1,75 @@ #!/usr/bin/env ruby require "rss" require "open-uri" FEED_URL = "https://feeds.pinboard.in/rss/u:DCE/" index = (ARGV.pop || 1).to_i content = [] links = [] refs = [] item_content = ->(item) do <<~OUT * [#{item.title}][#{index}] > #{item.description.tr("\n", " ").squeeze(" ")} OUT end item_link = ->(item) do "[#{index}]: #{item.link}" end add_item = ->(item) do ref = `bin/archive "#{item.link}"`.gsub("references:\n", "") content << item_content[item] links << item_link[item] refs << ref index += 1 end result = -> do <<~OUT --- #{content.join("\n")} #{links.join("\n")} --- references: #{refs.join} OUT end process_item = ->(item) do puts <<~OUT #{item_content[item]} #{item_link[item]} OUT print "Include? (y/n/a): " case gets.chomp when "y" add_item[item] when "n" nil when "a" puts result.call abort else process_item[item] end end URI.parse(FEED_URL).open do |rss| feed = RSS::Parser.parse(rss) feed.items.each do |item| process_item[item] end end