Skip to content

Instantly share code, notes, and snippets.

@psy-q
Created December 23, 2016 16:29
Show Gist options
  • Select an option

  • Save psy-q/562422b21191e2dfa61fa692c23a320d to your computer and use it in GitHub Desktop.

Select an option

Save psy-q/562422b21191e2dfa61fa692c23a320d to your computer and use it in GitHub Desktop.
Random Picker 2000
filename = ARGV[0]
if !filename || filename == ''
puts 'Give the path to JSON comments file as downloaded from e.g. https://www.reddit.com/r/RandomActsOfGaming/comments/4ijyqj.json'
exit 1
end
comment_json = JSON.parse(File.read(filename))
comment_nodes = comment_json.last['data']['children']
comment_data = comment_nodes.collect do |node|
node['data']
end
comments = comment_data.map do |data|
{ author: data['author'],
comment: data['body'] }
end
puts "Found #{comments.count} authors, selecting one randomly:\n\n"
winner = comments.sample
puts "And the winner is: /u/#{winner[:author]}, saying '#{winner[:comment]}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment