Created
December 23, 2016 16:29
-
-
Save psy-q/562422b21191e2dfa61fa692c23a320d to your computer and use it in GitHub Desktop.
Random Picker 2000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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