Skip to content

Instantly share code, notes, and snippets.

@bankair
Created September 20, 2017 08:34
Show Gist options
  • Save bankair/4cc2cbb171251ac42683ba7dbbb496fc to your computer and use it in GitHub Desktop.
Save bankair/4cc2cbb171251ac42683ba7dbbb496fc to your computer and use it in GitHub Desktop.
Try to find and display sentences generated by the Corporate Bullshit Generator (http://cbsg.sf.net/) matching specific keywords
require 'open-uri'
require 'nokogiri'
require 'colorize'
def fetch(keywords)
bullshits = Nokogiri::HTML(open('http://cbsg.sourceforge.net/cgi-bin/live'))
.css('font ul li')
.map { |node| node.children.first.content }
return bullshits if keywords.empty?
bullshits.select do |txt|
keywords.any? { |keyword| txt.downcase.index(keyword.downcase) }
end
end
def fetch_candidates(keywords)
10.times.each_with_object([]) do |_i, candidates|
candidates.concat(Array(fetch(keywords)))
end
end
puts(fetch_candidates(ARGV).map do |str|
"\n> " + str.split(' ').map do |word|
if ARGV.any? { |keyword| word.downcase.index(keyword.downcase) }
word.yellow
else
word
end
end .join(' ')
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment